javascript - AngularJS validation select box -
have selectbox in form, try make validate not work same before input type text. wrong ?
example
<div class="form-group"> <label class="control-label col-sm-3">email<sup>*</sup></label> <div class="col-sm-6"> <div class="input-icon-right"> <i class="fa fa-envelope"></i> <input class="form-control" placeholder="example@example.com" type="email" ng-model="patient.email" name="email" required> <p ng-show="myform.email.$error.required" style="color:red" ng-if="myform.email.$touched">add email</p> </div> </div> </div>
this code work , show error message when field empty.
and code select box no work correctly, every time select no empty have choice -select-, how can show error when no chice another.
<div class="form-group"> <label class="col-sm-3 control-label">{{getword('gender')}}<sup>*</sup></label> <div class="col-sm-6"> <select ui-select2 ng-model="patient.gender" data-placeholder="tên cơ sở" ng-change="changegender()" style="width: 100%;" requied name="gender"> <option value="">-{{getword('select')}}-</option> <option ng-repeat="item in genders" value="{{item.name}}"> {{getword(item.name)}} </option> </select> <p ng-show="myform.gender.$error.required" style="color:red" ng-if="myform.gender.$touched">please choice gender</p> </div> </div>
from understood. need show error when user have not selected or have not touched dropdown.
change line:
<p ng-show="myform.gender.$error.required" style="color:red" ng-if="myform.gender.$touched">please choice gender</p>
to this:
<p style="color:red" ng-if="myform.gender.$pristine || myform.gender.$error.required">please choice gender</p>
and there spelling mistake. change requied
required
correct too:
<select ui-select2 ng-model="patient.gender" data-placeholder="tên cơ sở" ng-change="changegender()" style="width: 100%;" requied name="gender">
to this:
<select ui-select2 ng-model="patient.gender" ng-change="changegender()" style="width: 100%;" required name="gender">
hope help.
Comments
Post a Comment