Skip to content

[Proposal]Add isValid method to FormState #108110

Description

@janosgy

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projecta: text inputEntering text in a text field or keyboard related problemsc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions