states_rebuilder icon indicating copy to clipboard operation
states_rebuilder copied to clipboard

Form validation

Open KKranjcevic opened this issue 1 year ago • 0 comments

If you have a text field in a form that depends on another text field, the validation doesn't work. I have a form called Reset Password with two fields: New Password and Repeat Password. The Repeat Password validation depends on the New Password text. It works fine if I set a new password and then repeat password, but if I return to the New Password field and want to change it, the Repeat Password will show an error(this is ok, because the password do not match enymore) . If I set the New Password to match the Repeat Password field again, the Repeat Password will not go through its validation because now it has an error, and the state has not changed. Despite the fields matching, the Repeat Password field still has an error until you change it.

The problem is in the i_base_form_field.dart file:

///Validate the input text by invoking its validator. bool validate([bool isFromSubmission = false]) { if (!isFromSubmission && _inj.hasError && _inj.oldSnapState?.data == _inj.snapValue.data) { return false; } ....

The if statement should be removed because it disables the validation check even though it should be performed. Alternatively, the validation should be changed to add an optional parameter that forces the validation, one that sets isFromSubmission to true.

This problem does not occur in version 5.2."

KKranjcevic avatar Mar 21 '23 21:03 KKranjcevic