-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Forms provide more control over when they validate. #7283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Callers can manually validate by calling validate(), or tell the Form to validate on every change by setting the `autovalidate` parameter. Fixes #7219
| Form({ | ||
| Key key, | ||
| @required this.child, | ||
| this.autovalidate: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be autoValidate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought so too, but grepping through the codebase, I found autofocus and autorefresh. There are no autoFoos anywhere. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was originally going to say that we should call this autoValidate for consistency with Flutter names in general, but if there's an established autopattern, then I guess we should stick with it.
| } | ||
| return false; | ||
| /// Validates every [FormField] that is a descendant of this [Form], and | ||
| /// returns true iff there are no errors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"if"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"iff" means if and only if, but if that's not widely known I can change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should have complete documentation, which means that if there was any other reason for it to return true, the paragraph would mention it. So the "and only if" is implied.
| void _handleSubmitted() { | ||
| FormState form = _formKey.currentState; | ||
| if (form.hasErrors) { | ||
| _autovalidate = true; // Start validating on every change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this code may serve as a cut-and-pasteable example maybe it would be better to only set _autovalidate true in the !form.validate() clause.
| } | ||
|
|
||
| /// Saves every FormField that is a descendant of this Form. | ||
| /// Saves every [FormField] that is a descendant of this [Form]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[this is just a nit] I don't think you really mean descendant here? If the Form contained other forms as well as fields, you're not going to recursively find all the fields, right? It looks like the term "descendant" is used in several places where you mean "child".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean "descendant that is not a descendant of a deeper Form" but that's a mouthful. FormFields will register themselves with the closest ancestor Form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose it will not confuse anyone. You could say "immediate descendant", or "FormFields registered with this form" but it was only a nit.
LGTM too.
Callers can manually validate by calling validate(), or tell the Form to
validate on every change by setting the
autovalidateparameter.Fixes #7219