I don't succeed in creating a basic Cross field validation for my form with Angular 2 rc.6.
constructor(private fb: FormBuilder) {
this.signUpForm = fb.group({
"firstName": ["", Validators.required],
"lastName": ["", Validators.required],
"email": ["", [Validators.required, ValidationService.emailValidator]],
"password": ["", [Validators.required, ValidationService.passwordValidator]],
"passwordConfirm": ["", [Validators.required]]
}, {validator: this.matchingPasswords('password', 'confirmPassword')});
this.firstName = this.signUpForm.controls["firstName"];
this.lastName = this.signUpForm.controls["lastName"];
this.email = this.signUpForm.controls["email"];
this.password = this.signUpForm.controls["password"];
this.passwordConfirm = this.signUpForm.controls["passwordConfirm"];
}
matchingPasswords(passwordKey: string, confirmPasswordKey: string) {
return (group: ControlGroup): {[key: string]: any} => {
let password = group.controls[passwordKey];
let confirmPassword = group.controls[confirmPasswordKey];
if (password.value !== confirmPassword.value) {
return {
mismatchedPasswords: true
};
}
}
}
I have seen the post Cross field validation in Angular2 but the point is that I am using Angular 2 rc.6.
With Angular 2 rc.6, ControlGroup is no more available from @angular/common and is not part of the updated @angular/forms where I get the FormBuilder, Validators, AbstractControl, FormGroup
.
It results that my method matchingPasswords
is not working anymore and I cannot check that the two passwords match.
Do you guys know what should I use instead of ControlGroup ?