Skip to content

Commit f726372

Browse files
committed
Form child components not populating
1 parent fe5afc2 commit f726372

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

client/packages/lowcoder/src/comps/comps/formComp/formComp.tsx

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -208,17 +208,13 @@ const FormBaseComp = (function () {
208208
);
209209
})
210210
.setPropertyViewFn((children) => {
211-
const editorContext = useContext(EditorContext);
212-
const isLogicMode = editorContext.editorModeStatus === "logic" || editorContext.editorModeStatus === "both";
213-
const isLayoutMode = editorContext.editorModeStatus === "layout" || editorContext.editorModeStatus === "both";
214-
215211
return (
216212
<>
217213
<Section name={sectionNames.basic}>
218214
{children.resetAfterSubmit.propertyView({ label: trans("formComp.resetAfterSubmit") })}
219215
</Section>
220216

221-
{isLogicMode && (
217+
{(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && (
222218
<><Section name={sectionNames.interaction}>
223219
{children.onEvent.getPropertyView()}
224220
{disabledPropertyView(children)}
@@ -229,22 +225,22 @@ const FormBaseComp = (function () {
229225
</>
230226
)}
231227

232-
{isLayoutMode && (
228+
{(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && (
233229
<>
234230
<Section name={sectionNames.layout}>
235231
{children.container.getPropertyView()}
236232
</Section>
237233
</>
238234
)}
239235

240-
{isLogicMode && (
236+
{(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && (
241237
<Section name={sectionNames.advanced}>
242238
{children.initialData.propertyView({ label: trans("formComp.initialData") })}
243239
{children.invalidFormMessage.propertyView({ label: trans("formComp.invalidFormMessage") })}
244240
</Section>
245241
)}
246242

247-
{isLayoutMode && (
243+
{(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && (
248244
<>
249245
<Section name={sectionNames.style}>
250246
{children.container.stylePropertyView()}
@@ -289,7 +285,8 @@ let FormTmpComp = class extends FormBaseComp implements IForm {
289285
}
290286
traverseFormItems(consumer: (item: GridItemComp) => boolean) {
291287
return traverseCompTree(this.getCompTree(), (item) => {
292-
return item.children.comp.children.formDataKey ? consumer(item as GridItemComp) : true;
288+
const hasFormDataKey = item.children.comp.children.hasOwnProperty("formDataKey");
289+
return hasFormDataKey ? consumer(item as GridItemComp) : true;
293290
});
294291
}
295292
validateFormItems() {
@@ -333,12 +330,19 @@ let FormTmpComp = class extends FormBaseComp implements IForm {
333330
// For the properties, first find in data, then initialData, subcomponent default value (resetValue), empty value (clearValue)
334331
const newData = { ...(initialData ?? this.children.initialData.getView()), ...data };
335332

333+
// Only proceed if we have data to set
334+
if (!Object.keys(newData).length) {
335+
return Promise.resolve();
336+
}
337+
336338
return this.runMethodOfItems(
337339
{
338340
name: "setValue",
339341
getParams: (t) => {
340342
// use component name when formDataKey is empty
341-
const key = t.children.comp.children.formDataKey?.getView() || t.children.name.getView();
343+
const formDataKey = t.children.comp.children.formDataKey?.getView();
344+
const componentName = t.children.name.getView();
345+
const key = formDataKey || componentName;
342346
const value = newData[key];
343347
return value !== undefined ? [value as EvalParamType] : undefined;
344348
},
@@ -347,7 +351,9 @@ let FormTmpComp = class extends FormBaseComp implements IForm {
347351
name: "setRange",
348352
getParams: (t) => {
349353
// use component name when formDataKey is empty
350-
const key = t.children.comp.children.formDataKey?.getView() || t.children.name.getView();
354+
const formDataKey = t.children.comp.children.formDataKey?.getView();
355+
const componentName = t.children.name.getView();
356+
const key = formDataKey || componentName;
351357
const value = newData[key] ? newData[key] : undefined;
352358
return value !== undefined ? [value as EvalParamType] : undefined;
353359
},
@@ -387,7 +393,8 @@ let FormTmpComp = class extends FormBaseComp implements IForm {
387393
case CompActionTypes.UPDATE_NODES_V2: {
388394
const ret = super.reduce(action);
389395
// When the initial value changes, update the form
390-
requestAnimationFrame(() => {
396+
if (action.value["initialData"] !== undefined) {
397+
queueMicrotask(() => {
391398
this.dispatch(
392399
customAction<SetDataAction>(
393400
{
@@ -398,6 +405,7 @@ let FormTmpComp = class extends FormBaseComp implements IForm {
398405
)
399406
);
400407
});
408+
}
401409
return ret;
402410
}
403411
case CompActionTypes.CUSTOM:
@@ -548,4 +556,4 @@ export function defaultFormData(compName: string, nameGenerator: NameGenerator):
548556
showFooter: true,
549557
},
550558
};
551-
}
559+
}

client/packages/lowcoder/src/comps/comps/textInputComp/textInputConstants.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ export const useTextInputProps = (props: RecordConstructorToView<typeof textInpu
183183
props.value.onChange(defaultValue)
184184
}, [defaultValue]);
185185

186+
useEffect(() => {
187+
if (!changeRef.current) {
188+
setLocalInputValue(inputValue);
189+
}
190+
}, [inputValue]);
191+
186192
useEffect(() => {
187193
if (!changeRef.current) return;
188194

@@ -214,6 +220,7 @@ export const useTextInputProps = (props: RecordConstructorToView<typeof textInpu
214220
debounce(function (value: string, valueCtx: any) {
215221
propsRef.current.value.onChange(value);
216222
propsRef.current.onEvent("change");
223+
changeRef.current = false; // Reset after commit
217224
}, 1000)
218225
);
219226

0 commit comments

Comments
 (0)