How can I get untouched status change when click enter in a inputbox

82 views Asked by At

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?

enter link description here

0

There are 0 answers