angularjs - Validate an input field in HTML having 2 buttons. Validate only for one button click -


this html file. there no used in this. there 2 buttons in html. using angularjs2( typescript )

<div class="visitor-entry form-group">     <!-- [ngclass]="{'validate':vname.errors && (vname.dirty || vname.touched)}"-->     <div class="ui-input-group">         <input #vname="ngmodel" type="text" class="form-control" placeholder="name*" name="visitorname" [(ngmodel)]="visitorname">         <span class="input-bar"></span>     </div>     <div class="ui-input-group">         <input type="text" class="form-control" placeholder="mobile" name="visitormob" [(ngmodel)]="visitormob">         <span class="input-bar"></span>     </div>     <div class="add-btn-cont">         <button [disabled]="vname.errors" class="icon-btn" id="addvisitor" title="add" (click)="addvisitor();"></button>     </div> </div>  <div class="block search-add-list active">     <h6>person affected           <button class="icon-btn pull-right addnewbtn" title="add new" data-toggle="modal" id="personaffectedbtn" (click)="addnewperson(personaffectedcode)></button>         </h6> </div> 

here want validate visitorname field mandatory, , add class [ngclass]="{'validate':vname.errors && (vname.dirty || vname.touched)}. . should validated first button click.

but if add required visitorname field validating both button clicks.

how can solve issue.

you can set value of required on button click

<div class="visitor-entry form-group" >   <!-- [ngclass]="{'validate':vname.errors && (vname.dirty || vname.touched)}"-->   <div class="ui-input-group"  >     <input #vname="ngmodel" type="text"  class="form-control" placeholder="name*" name="visitorname" [(ngmodel)]="visitorname" [ngclass]="{'validate':vname.errors && (vname.dirty || vname.touched)}" [required]="{{reqval}}">     <span class="input-bar"></span>   </div>   <div class="ui-input-group">     <input type="text" class="form-control" placeholder="mobile" name="visitormob" [(ngmodel)]="visitormob">     <span class="input-bar"></span>   </div>   <div class="add-btn-cont">     <button  [disabled]="vname.errors" class="icon-btn" id="addvisitor" title="add" (click)="addvisitor();reqval=false"></button>   </div> </div>  <div class="block search-add-list active">     <h6>person affected       <button class="icon-btn pull-right addnewbtn" title="add new" data-toggle="modal" id="personaffectedbtn" (click)="addnewperson(personaffectedcode);reqval=true"></button>     </h6> </div> 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -