Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset particular field [React-admin]

I would like to reset particular field (element) of SimpleForm from react-admin v4

At the moment the form have 3 related field like:

  • A
  • B
  • C

When you select A the select B is enabling and when B the same if for the C. The happy flow works very well.

Currently I'm using the FormDataConsumer so fields are dependent.

The problem is when user decide change element A or B. Then the form is not reloading again and the source is still the same.

So for example:

User selected A, field_a = X, then selected B, field_b = Y, then selected C, field_c = Z

Then the A has been updated so the result is the following:

  • field B is clear (only from UI perspective) because the formData.field_a is still set
  • field C is still set.

Do you have any ideas how to set the data base on onChange action?

I tried to use the refs, react-hook-form and register.

Is it any way to reset one field or many fields form form?

The form based on Input Components and <SimpleForm> provided by React-admin

like image 985
Daniel Avatar asked Aug 13 '26 20:08

Daniel


1 Answers

The useForm() / useFormContext() hooks return a method: resetField("fieldName")

https://react-hook-form.com/api/useform/resetfield

like image 73
MaxAlex Avatar answered Aug 15 '26 13:08

MaxAlex