flutter-form-builder-ecosystem / flutter-form-builder-ecosystem/form_builder_validators

FormBuilderValidators.equal() do not update value to compare

Open
#63 4 comments 1 reaction 0 assignees View on GitHub
bug help wanted
Dominant language
Dart
Stars
67
Forks
106
Avg merge
2d 21h
Merged PRs (30d)
1

Description

### Discussed in https://github.com/flutter-form-builder-ecosystem/form_builder_validators/discussions/61

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:

```dart
FormBuilderTextField(
name: 'password',
decoration: InputDecoration(labelText: 'Password'),
obscureText: true,
validator: FormBuilderValidators.compose([
FormBuilderValidators.required(),
FormBuilderValidators.minLength(6)
])),
FormBuilderTextField(
name: 'confirmPassword',
decoration: InputDecoration(labelText: 'Confirm Password'),
obscureText: true,
validator: FormBuilderValidators.compose([
FormBuilderValidators.required(),
FormBuilderValidators.minLength(6),
(value) {
print(
"value: $value matches ${_formKey.currentState?.instantValue['password']}");
return null;
},
FormBuilderValidators.equal(
_formKey.currentState?.instantValue['password'] ?? '',
errorText: 'Passwords do not match')
])),
```

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:

```dart
FormFieldValidator equal(
Object? value, {
String? errorText,
}) =>
(T? valueCandidate) {
print(
'value: $value valueCandidate: $valueCandidate'
);
// Value is null and valueCandidate the form field value, when update field value
return valueCandidate != value ? errorText : null;
};
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.