I am facing an issue with the default required validator in angular forms. My form has one input field and a submit button.
There are two important files:
example.form.ts
example.form.template.html
Here is my code setup:
In the .ts file, I create a form using the form builder:
exampleForm: FormGroup
constructor(protected fb: FormBuilder){
this.exampleForm = fb.group({
name: ['', Validators.required]
});
}
get isFormValid: boolean {
return this.exampleForm.valid;
}
Template section:
<form [formGroup]="exampleForm">
<input type="text" formControlName="name">
<button type="submit" [disabled]="!isFormValid" id="save-button">Submit</button>
</form>
Currently, when the input field is empty, the button stays disabled (as per the validator). But even if I enter something into the field, I can't directly click on the button - I have to first click outside the input field. How can I modify this behavior?