react-admin
react-admin copied to clipboard
Disabling and enabling form Inputs breaks their isDirty state
What you were expecting: When using a form input that is conditionally enabled/disabled by a switch:
- Changing the input's value triggers validation and marks the field as dirty (i.e.,
isDirtybecomestrue). - Disabling the input should reset
isDirtytofalsesince validation shouldn't run on disabled inputs. - Re-enabling the input should allow it to become dirty again when its value is changed, triggering validation as expected.
What happened instead:
After re-enabling a previously disabled input, changing its value does not set isDirty to true, and validation is not triggered for that field.
Steps to reproduce:
- Create a form with an input field that has validation and can be disabled/enabled based on a switch or another condition.
- Change the value of the input and observe that validation runs as expected.
- Disable the input, then re-enable it using the switch.
- Change the input value again. Notice that validation does not run, and the field does not become dirty.
Reproduction Link:
In this example, after toggling the switch, the "title" field can be submitted with an empty value, even though it is marked as required.
Other information:
After investigating, I believe this issue is caused by this PR. When the input is re-enabled, disabled = undefined is passed to react-hook-form's controller, but it seems the controller doesn't fully clear the disabled state internally, preventing the field from becoming dirty again.
Does the original issue with react-hook-form that the workaround was intended to fix still persist?
It seems like it was fixed here maybe we can remove that workaround.