Closed Starojitski closed 7 years ago
The problem is that email validator wrongly validated initial value to invalid.
I was building reactive form for a subscriber (a model acquired from a service): in component.ts
component.ts
let email = subscriber.Email; ... Email: this.formBuilder.control(email, [Validators.required, CustomValidators.email]),
in template:
<div class="form-group" [ngClass]="{ 'has-error': f.submitted && !emailControl.valid}"> <input id="email" type="email" class="form-control" formControlName="Email"/> <div>{{emailControl.errors|json}} - {{emailControl.valid}}</div> <div *ngIf="f.submitted && !emailControl.valid" class="help-block">Email is required</div> </div>
produces if i edit the field but leave the same email then validation changes to
If use hardcoded email value:
let email = 'hardcoded@email.com'; ... Email: this.formBuilder.control(email, [Validators.required, CustomValidators.email]),
then i have no problem
How do i solve this?
found the problem! it turns out that the email was padded with spaces which i could not see in console.log.
The problem is that email validator wrongly validated initial value to invalid.
I was building reactive form for a subscriber (a model acquired from a service): in
component.ts
in template:
produces if i edit the field but leave the same email then validation changes to
If use hardcoded email value:
then i have no problem
How do i solve this?