Here is simple input box in a reactive form: Html:
<form [formGroup]="form" (ngSubmit)="onSubmit()">
<input type="text" formControlName="box" (keyup.enter)="dosomething()">
<button>Submit</button>
</form>
TS:
dosomething() {
this.cd.detectChanges(); // private *cd*: ChangeDetectorRef
console.log(this.form.untouched);
}
onSubmit() {
console.log('from submit: ', this.form.untouched);
}
input something in the input box
-> click enter, I got: true;
-> click the submit button, I got: false
In this case, cz the input box has already been touched, so, we should expect the false.
How can I get the false when clicking enter in the input box?