Closed jmtudela closed 11 months ago
This is happening because the value in the first field is invalid and therefore we do not save it (the empty state). We cannot save error states like this or we would be saving invalid states. If you were to change the first field to something valid, this wouldn't happen.
Could you explain a little bit more about what you are trying to do here and we may be able to suggest a solution or workaround?
I'm not saving anything when the Field A is restored, and even if I would force a validation (not a save) the value should not be restored. In any case, if you do it the other way, clear Field A and choose Option 2, which is a valid combination, Field A value gets restored.
We mean could you explain a little more about your use case, so we could try to give you an alternative solution. The only reason this is happening is because you have configured the validation so that field A is required, and you're setting it to an invalid state in your example here, then moving on and changing field B which causes your conditions to run, and in turn causes field A to remount because you changed something about it.
If you set field A to any valid value, then you'll notice that this behaviour of resetting the field to it's previous value doesn't happen.
As explained, it because conditionals are remounting the field when apply new validation rules, which causes the field to re-render itself, pulling it's value from form state again. This will be the last valid value, which is not the invalid empty state.
Your options are:
Sorry, but I don't get the point. The idea is to require Field A only if Option 1 is selected on Field B. I attach two more examples to be more clear.
Example 1: example1.gz In this example you can clear Field A, modify another field (required message appears but don't reset Field A), and then change Field B what resets Field A.
Example 2: example2.gz In this example Field A must be empty if Field B = Option 1, this does not resets Field A. If conditionals are remounting the field when apply new validation rules, why in this example doesn't do it?
Checklist
Hosting
Describe the bug If conditional UI is used to make a validation of a field A based on the value of a field B, when you empty field A and then change value of field B the value of the field A is restored.
To Reproduce See attached gif and app export.
Expected behavior Field A should remain empty.
Screenshots
App Export app_example.gz
Desktop (please complete the following information):
From SyncLinear.com | BUDI-7465