flutter_form_builder icon indicating copy to clipboard operation
flutter_form_builder copied to clipboard

Listen for all fields are valid without show errors

Open hienhodeveloper opened this issue 4 years ago • 3 comments

I want to disable/enable submit button when all fields are validated correctly. How can I archive it? I try using "onChanged" like this. It works, but I don't want all my fields to show errors for every changed

`FormBuilder( key: _formKey, onChanged: () { var newIsValid = _formKey.currentState?.validate() ?? false; if (newIsValid != isValid) { setState(() { isValid = newIsValid; }); } },

child: Column()`

hienhodeveloper avatar May 07 '21 01:05 hienhodeveloper

i want to know too , how ?

YouSour avatar May 11 '21 01:05 YouSour

Has a some solutions for this, every of them depends of state management. You can take a look in autovalidateMode

deandreamatias avatar Jun 10 '22 13:06 deandreamatias

In my opinion that's should be the default behaviour. I.e. disabled button clearly indicates that the form is yet to complete, but fields' error boxes aren't screaming about fields that user hasn't time to fill.

Probably validation should be split into two parts – "validation state" and "showing validation errors". Then this behaviour could be just one more AutovalidateMode constant.

divan avatar Jun 30 '22 21:06 divan

I think you can use _formKey.currentState?.isValid instead of validate() method

bb-renittojose avatar Nov 09 '22 17:11 bb-renittojose