This feature was already requested in #48874 , and was partially developed in #48948
However, the part about having the isValid method on the FormState was rejected, because if we use it to disable the "submit" button, the user might not know what the errors are. #48948 (comment)
I believe this was a good choice back then, but now we have autovalidateMode: AutovalidateMode.onUserInteraction where the error message would show up at the correct time.
Therefore I'm asking you to re-evaluate this feature request.
@tjonganthony I copied your original Use case and Proposal which were perfect descriptions. I hope it's fine.
Use case
FormState.validate causes all field to be validated even though the field has never been touched. There are cases when I want to only check whether the current form is valid without triggering UI changes on all the field.
For example:
I have a Form with 15 FormField and a submit button. I want to enable/disable the submit button based on whether there's a field that is notValid.
so I added onChanged: _updateSubmitButton() and _updateSubmitButton() will use the value from formKey.currentState.validate() to determine whether to enable or disable the submit button.
This will cause changing field 1 to make all the 15 fields to be validated and maybe show error just in order for me to disable the submit button.
Proposal
Add an isValid() method to FormState that will check whether all the field is valid.
This will also require isValid() to be added to FormFieldState in order not to rely on FormFieldState.validate() which will cause the error text to appear.
This feature was already requested in #48874 , and was partially developed in #48948
However, the part about having the
isValidmethod on the FormState was rejected, because if we use it to disable the "submit" button, the user might not know what the errors are. #48948 (comment)I believe this was a good choice back then, but now we have
autovalidateMode: AutovalidateMode.onUserInteractionwhere the error message would show up at the correct time.Therefore I'm asking you to re-evaluate this feature request.
@tjonganthony I copied your original Use case and Proposal which were perfect descriptions. I hope it's fine.
Use case
FormState.validatecauses all field to be validated even though the field has never been touched. There are cases when I want to only check whether the current form is valid without triggering UI changes on all the field.For example:
I have a
Formwith 15FormFieldand a submit button. I want to enable/disable the submit button based on whether there's a field that is notValid.so I added
onChanged: _updateSubmitButton()and_updateSubmitButton()will use the value fromformKey.currentState.validate()to determine whether to enable or disable the submit button.This will cause changing field 1 to make all the 15 fields to be validated and maybe show error just in order for me to disable the submit button.
Proposal
Add an
isValid()method toFormStatethat will check whether all the field is valid.This will also require
isValid()to be added toFormFieldStatein order not to rely onFormFieldState.validate()which will cause the error text to appear.