You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Form fields in autovalidate form are validated on the second build (but not the first) #15404
If you have a TextFormField with a validator in a Form with autovalidate set to true, the validator is not evaluated when the form field is first created, but it is evaluated the next time the Form builds, even if that happens for unrelated reasons (e.g. an animation, or a reassemble during hot reload). So for example this means that hot-reloading an auto-validate form will make all the validators trigger and all the text fields turn red.
changed the title [-]TextFormField shows error text when it rebuilds[/-][+]Form fields in autovalidate form are validated on the second build (but not the first)[/+]on Mar 11, 2018
I think we should reimplement autovalidate by having the build methods of fields check if it's set and if so validate themselves, rather than having the form do it.
Why TextFormField is auto-validating itself without updating its content? I have autovalidate set to true, but is this expect to happen?
Note: this is causing my all my fields red without updating its content.
I have found this many times. I see it has a design-flaw/bug. Their is no way anyone would want an entire form to autovalidate and show errors as soon as it is displayed.
Reacted by Pedro Massango, Vlad, Bruno Leroux, Ethel, Allan Wolski, F. S., Sven Mathieu, Sait Banazılı, Dorian Gruselin and Julian Aßmann
Yes i agree. I think autovalidate should only run when a field value changes.
I just did a workaround, using GlobalKey<FormFieldState> and I just run the validation on the onChanged property:
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.
Activity
[-]TextFormField shows error text when it rebuilds[/-][+]Form fields in autovalidate form are validated on the second build (but not the first)[/+]Hixie commentedon Mar 12, 2018
I think we should reimplement autovalidate by having the build methods of fields check if it's set and if so validate themselves, rather than having the form do it.
meggamind commentedon Apr 6, 2018
@Hixie : I would like to take this issue. I will try to reproduce this issue and get back to you. Is there a demo app that already shows this issue ?
HansMuller commentedon Apr 6, 2018
I think you'll be able to reproduce the problem with the gallery TextField demo, https://github.com/flutter/flutter/blob/master/examples/flutter_gallery/lib/demo/material/text_form_field_demo.dart
Thanks for taking this on!
zoechi commentedon Jan 16, 2019
I wasn't able to reproduce with Gallery.
A hot-reload doesn't trigger validation, only clicking the [SUBMIT] button.
I don't close because I'm not 100% sure I understand what the issue is.
li2 commentedon Feb 10, 2019
_autovalidate won't work without
setState, see attached image,line 107 https://github.com/flutter/flutter/blob/master/examples/flutter_gallery/lib/demo/material/text_form_field_demo.dart
jeisux92 commentedon Apr 18, 2020
if the Form Widget is set to
autovalidatethe validator is exectuted at first time, I think it's a bugpedromassango commentedon May 5, 2020
@jeisux92 did you found a workaround for this bug?
pedromassango commentedon May 5, 2020
Why
TextFormFieldis auto-validating itself without updating its content? I haveautovalidateset to true, but is this expect to happen?Note: this is causing my all my fields red without updating its content.
@Hixie is this a expected behaviour?
slightfoot commentedon May 5, 2020
I have found this many times. I see it has a design-flaw/bug. Their is no way anyone would want an entire form to autovalidate and show errors as soon as it is displayed.
SaulPT commentedon Jun 2, 2020
Yes i agree. I think
autovalidateshould only run when a field value changes.I just did a workaround, using
GlobalKey<FormFieldState>and I just run the validation on theonChangedproperty:pedromassangocode commentedon Jul 16, 2020
This is reproducible in
1.20.0-7.1.pre.Complete sample code
flutter doctor -v
github-actions commentedon Aug 15, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.