Search code examples
formsangularsubmitrequiredfieldvalidator

angular2 form validator by pressing enter


I have a form submitted by pressing enter. but when I press enter , the form is submitted but the validators are not run

<form [ngFormModel]="form"  (keyup.enter)="updateApplicationLink()">
   <input  [(ngModel)]="table.labelFR"   ngControl="labelfr">

constructor(fb: FormBuilder) {
  this.form= fb.group({
      labelfr: new Control('', Validators.required)
  });

Solution

  • try this for required validation:

    <input ng-model="labelFR" required>
    <h1>{{form.labelFR.$valid}}</h1>