0

I followed same sample with the code and tried to show validation when user removes the text in the input and show display messages.Unfortunately, when I remove the text field it does not show anything. Could you please check the code and tell me why I can not show the validation message ?

Regards Alper

 <label for="name">SA / Rentennummer 005 :</label>
 <input type="text" class="form-control" id="name" required 
  [(ngModel)]="Input.name" name="name"  #name="ngModel">
 <div [hidden]="name.valid || name.pristine"
     class="alert alert-danger">
    name is required
  </div>

In The typescript :

  Input= { name:'Alper'};
1
  • can you create a sample plunker? Commented Mar 28, 2017 at 9:00

1 Answer 1

1
   form : FormGroup;
   this.form = fb.group({
      name : new FormControl({value: null}, Validators.compose([Validators.required, Validators.maxLength(100)]))
    });


    <form class="form-details" role="form" name="registrationForm" [formGroup]="userForm">
            <div>
                <div class="row input-label">
                  <label class="form-label" for="name">First name</label>
                  <input
                    [formControl]="form.controls['name']"
                    type="text"
                    class="form-control"
                    id="form"
                    name="form">
                </div>
                <div *ngIf="!form.controls['name'].valid">field is required</div>
            </div>
          </form>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.