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
FormBuilderValidators.equal() do not update value to compare #63
Originally posted by orbiteleven August 30, 2023
Using form_builder_validators with flutter_form_builder and I have what I think should be a pretty common password+confirm password form, but I'm a bit confused. This is what I have so far:
the "custom" validator works fine, but FormBuilderValidators.equal() throws an error. What am I doing wrong?
For some reason, FormBuilderValidators.equal validator don't update value to compare with fieldValue
A nice way to show the error, is create a validate method with print:
FormFieldValidator<T> equal<T>(
Object? value, {
String? errorText,
}) =>
(T? valueCandidate) {
print(
'value: $value valueCandidate: $valueCandidate'
);
// Value is null and valueCandidate the form field value, when update field valuereturn valueCandidate != value ? errorText :null;
};
Unfortunately I don't have a solution, but here is what I found out.
Apparently he does not get the new value or any value for the matching value. The cascading thing which keeps on going. I don't know what could cause that.
When I add a setState() to the confirmPassword field on the onChange callback it works fine.
This is the Widget with what I tested.
What seems to also works is this:
(value) {
returnFormBuilderValidators.equal<String>(
_formKey.currentState?.instantValue['password'] ??'',
errorText:'Passwords do not match first one')(value);
},
I think that the equal Funkton a Closure returns which saves the initial value (also tried it with another value and then I don't get the weird cascading String). Since the State is never set in the Component the value is never reevaluated.
I hope this helps, if anything is unclear please ask me anything and I will try to help.
Reacted by Lvim Tech, Emmett Deen and Lennart Bjugg
Activity
the-devbear commentedon Nov 10, 2023
Unfortunately I don't have a solution, but here is what I found out.

Apparently he does not get the new value or any value for the matching value. The cascading thing which keeps on going. I don't know what could cause that.
When I add a

setState()to theconfirmPasswordfield on theonChangecallback it works fine.This is the Widget with what I tested.
What seems to also works is this:
(value) { return FormBuilderValidators.equal<String>( _formKey.currentState?.instantValue['password'] ?? '', errorText: 'Passwords do not match first one')(value); },I think that the
equalFunkton a Closure returns which saves the initial value (also tried it with another value and then I don't get the weird cascading String). Since the State is never set in the Component the value is never reevaluated.I hope this helps, if anything is unclear please ask me anything and I will try to help.
thedavidpeto commentedon Jul 15, 2024
Is there an update about this? As I see this is still an issue in the latest version
11.0.0?Johannes-Schiel commentedon Feb 13, 2025
i also have the same problem i now created my own code for this.
hungtrn75 commentedon Mar 4, 2025
You can use my solution