You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the FormBuilder with the renderFormFields function, I am unable to set default or prefilled values when editing a form. Despite passing currentRow as the initial values, the form fields do not update properly in edit mode.
Steps to Reproduce
Use the FormBuilder to render a form dynamically from a JSON schema.
Pass the currentRow data object to the form as default or prefilled values.
Observe that the fields remain empty instead of populating with the currentRow data.
Example Code
constdefaultVals=generateDefaultValues(categoryFormFields);constformSchema=generateZodSchema(categoryFormFields);constform=useForm<z.infer<typeofformSchema>>({resolver: zodResolver(formSchema),defaultValues: defaultVals,});// Resetting form values for edit modeuseEffect(()=>{if(open&¤tRow){form.reset(currentRow);// Doesn't populate fields}},[open,currentRow,form]);// Rendering form fields<Form{...form}><formid="category-form"onSubmit={form.handleSubmit(onSubmit)}>{renderFormFields(categoryFormFields,form)}</form></Form>
This code letting it to produce infinite render error
Expected Behavior
When currentRow is provided, the form fields should populate with the data from currentRow.
The renderFormFields function should correctly bind the data to the corresponding form fields.
Observed Behavior
Form fields remain empty in edit mode, even when currentRow has valid data.
The renderFormFields function does not seem to recognize the updated values passed through form.reset.
This when we create data
This when we Edit data
but the values are not setting on the fields
Additional Context
The issue might be related to how renderFormFields handles the defaultValues or reset functionality from React Hook Form.
The form works correctly in "create mode" (default values), but fails to update when switching to "edit mode".
The text was updated successfully, but these errors were encountered:
When using the
FormBuilder
with therenderFormFields
function, I am unable to set default or prefilled values when editing a form. Despite passingcurrentRow
as the initial values, the form fields do not update properly in edit mode.Steps to Reproduce
FormBuilder
to render a form dynamically from a JSON schema.currentRow
data object to the form as default or prefilled values.currentRow
data.Example Code
This code letting it to produce infinite render error
Expected Behavior
Observed Behavior
This when we create data
This when we Edit data
but the values are not setting on the fields
Additional Context
The text was updated successfully, but these errors were encountered: