I am using the built-in pipe titlecase on an input field - username in a reactive form. It is working properly only when i am typing in the input field and its not working when i select from the browser suggestion for that input field, even when i focused out.
app.component.ts
ngOnInit() {
this.signupForm = new FormGroup({
'userData': new FormGroup({
'username': new FormControl(null, [Validators.required, this.forbiddenNames.bind(this)]),
'email': new FormControl('abc@test.com', [Validators.required, Validators.email], this.forbiddenEmails)
}),
'gender': new FormControl('male'),
'hobbies': new FormArray([])
});
}
app.component.html
<form [formGroup]="signupForm" (ngSubmit)="onSubmit()">
<div formGroupName="userData">
<div class="form-group">
<label for="username">Username</label>
<input
type="text"
id="username"
formControlName="username"
class="form-control"
[value]="signupForm.get('userData.username').value | titlecase">
<span *ngIf="signupForm.get('userData.username').errors['required']">
This field is required
</span>
</div>
...
</div>
<button class="btn btn-primary" type="submit">Submit</button>
</form>
When i am typing it is working fine
When i am selecting from the browser selection it is not working
Though i focused out of the input field its still in uppercase.
Can someone help on what i am doing wrong.
@Haifeng Zhang This is the scenario i mentioned in the question, i replicated in your stackblitz demo