Open Dionnie123 opened 1 year ago
Could you create issues in dedicated repo for reactive forms generator https://github.com/artflutter/reactive_forms_generator
Check examples to understand how to use must match https://github.com/artflutter/reactive_forms_generator/blob/master/packages/reactive_forms_generator/example/lib/docs/login/login.dart
Thank you for quick response @vasilich6107 I solved the problem by creating a custom MustMatchValidator (the built-in one isn't working for me )
class MustMatchValidatorZ extends Validator<dynamic> {
final String controlName;
final String matchingControlName;
final bool markAsDirty;
const MustMatchValidatorZ(
this.controlName, this.matchingControlName, this.markAsDirty)
: super();
@override
Map<String, dynamic>? validate(AbstractControl<dynamic> control) {
final error = {ValidationMessage.mustMatch: true};
var form = {};
control.parent?.valueChanges.listen((event) {
form = event as Map<dynamic, dynamic>;
if (form[controlName] != form[matchingControlName]) {
control.setErrors(error, markAsDirty: markAsDirty);
control.markAsTouched();
} else {
control.removeError(ValidationMessage.mustMatch);
}
});
return null;
}
}
I'm not just sure if it's a good solution, but it's working smoothly!
Hi @Dionnie123,
Thanks for using Reactive Forms.
The MustMatchValidator
is intended to be used only at FormGroup level not at the FormControl
level.
Try using the built-in MustMatchValidator
at FormGroup level.
Hi @joanpablo We can close this issue