Skip to content

add isValid method to FormState #48874

Description

@tjonganthony

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

    c: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterf: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.

    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