angular - angular2 ngFormControl select not working -


my code fragment in .ts file

this.signupform= _fb.group({     'fname': ['',validators.compose([validators.required,ndformvalidation.alphaonly])]     'lname': ['',validators.compose([validators.required,ndformvalidation.alphaonly])],     'gender':['',validators.compose([validators.required,ndformvalidation.gender])] }); this.fname = this.signupform.controls['fname']; this.lname = this.signupform.controls['lname']; this.gender = this.signupform.controls['gender']; 

my code fragment in .html file

<form [ngformmodel]="signupform" (ngsubmit)="onsubmit(signupform.value)">       <div class="input-field">          <label for="txtfirstname">first name</label>          <input type="text" id="txtfirstname" [ngformcontrol]="fname" placeholder="john"/>          <span *ngif="fname.haserror('required') && fname.dirty">first name required</span>          <span *ngif="fname.value.length>2 && fname.haserror('invalidalphaonly') && fname.dirty">alphabets , space allowed </span>      </div>       <div class="input-field">          <label for="txtlastname">last name</label>          <input type="text" id="txtlastname" [ngformcontrol]="lname" placeholder="martin" />          <span *ngif="lname.haserror('required') && lname.dirty">first name required</span>          <span *ngif="lname.value.length>2 && lname.haserror('invalidalphaonly') && lname.dirty">alphabets , space allowed </span>      </div>        <div class="input-field">          <label for="cmbgender">gender</label>          <select id="cmbgender" [ngformcontrol]="gender">              <option *ngfor="#sex of genders" [value]="sex" >{{sex|uppercase}}</option>          </select>          <span *ngif="gender.haserror('required') && gender.dirty">gender required</span>          <span *ngif="gender.haserror('invalidgender') && gender.dirty">gender can male,female or other</span>      </div>       <button [disabled]="!signupform.valid || signupform.pristine" [class.nd-btn-disabled]="!signupform.valid || signupform.pristine" id="loginbutton" type="submit">sign up</button>      <button id="signupbutton" [routerlink]="['loginpage']" type="button" title="click login existing account">already have account?</button>   </form> 

my problem

ngformcontrol , validation working expected in fname , lname gender when change value of select in ng-pristine(not in ng-dirty state) , ng-invalid

<div class="input-field" _ngcontent-ybk-5="">     <label _ngcontent-ybk-5="" for="txtlastname">last name</label>     <input id="txtlastname" class="ng-dirty ng-valid ng-touched" type="text" _ngcontent-ybk-5="" placeholder="martin"> </div>  <label _ngcontent-ybk-5="" for="cmbgender">gender</label> <select id="cmbgender" class="ng-pristine ng-invalid ng-touched" _ngcontent-ybk-5=""> 

why change made <select> element not triggering..... can't figure out what's problem, can me or point out missing

as per martin comment

i ensure signupform.value not reflecting the change in <select> control adding following code

get checksignupformmodel() { return json.stringify(this.signupform.value); } 

out put of {{checksignupformmodel}}

{"fname":"max","lname":"pay",,"gender":""}

although change fname , lname text box being reflected in {{checksignupformmodel}} change gender has no affect

ndformvalidation.gender goes this

static gender(control:control){         console.log('sex',control.value);         if( control.value.match(/^(male|female|others)$/))             return null;         else             return {"invalidgender":true};     } 


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -