Reputation: 640
I'm trying to build a form with custom validations, here is an example:
this.registrationForm= fb.group({
dob: ['', Validators.required],
email: ['', Validators.compose([Validators.required, emailValidator])],
password: ['', Validators.required],
confirmPassword: ['', Validators.required],
firstName: ['', Validators.required],
lastName: ['', Validators.required]
}, {validator: matchingPasswords('password', 'confirmPassword')})
i have only one problem - the ng-invalid css class from the NgModel directive won't fire for the custom validator, anyone encountered with this problem?
Upvotes: 2
Views: 940
Reputation: 640
in the CSS file the 'ng-invalid' class associated with [required] so it won't fire without it and the custom Validator is not 'required'. for example:
<input required type=”text” ngControl=”username” />
Upvotes: 1