javascript - How to check validation on fields , selected values can not be same? -


i have check validation on 2 fields ng-change. selected values cannot same have implemented below logic function not being called. been hours , cannot figure out doing wrong. please check if logic being implemented correctly.

so far tried code....

main.html

<div class="panel-body">         <form name="addattesform" id="addattesform" novalidate k-validate-on-blur="false">                 <div class="row">                         <div class="form-group col-md-6">                             <label for="roletype" class="col-md-4">role type:</label>                             <div class="col-md-8">                                 <select                                      kendo-drop-down-list                                     data-text-field="'text'"                                     data-value-field="'id'" name="roletype"                                     k-option-label="'select'"                                     k-data-source="roletypedatasource"                                     ng-model="attestordto.riskassessmentroletypekey"                                     id="roletype">                                           </select>                                </div>                         </div>                 </div>                 <div class="row">                         <div class="form-group col-md-6">                                 <label for="attestorworker" class="col-md-4">attestor:</label>                             <div class="col-md-8">                                 <input type="text" class="form-control" id="attestorworker" required                                     ng-model="attestordto.attestorworker" name="attestorworker"                                     ng-change="validateproxy('attestorworker','proxyworker')"                                     ng-model-options="{updateon: 'blur'}"                                     ng-click="openattestorsearch()"  readonly="readonly"/>                             </div>                         </div>                 </div>                 <div class="row">                         <div class="form-group col-md-6">                                 <label for="proxyworker" class="col-md-4">proxy :</label>                             <div class="col-md-8">                                 <input type="text" class="form-control" id="proxyworker" required                                     ng-model="attestordto.proxyworker" name="proxyworker"                                     ng-model-options="{updateon: 'blur'}"                                     ng-click="openproxysearch()" ng-disabled="!attestordto.attestorworker" ng-change="validateproxy('attestorworker','proxyworker')" readonly="readonly"/>                                     <p class="text-danger" ng-show="addattesform.proxyworker.$error.daterange">attestor , proxy can not same</p>                             </div>                         </div>                 </div>                 <div class="row">                     <div class="col-md-6">                         <button class="btn btn-primary pull-right" type="button" ng-disabled="addattesform.$invalid" ng-click="saveattestor()">add attestor</button>                     </div>                 </div>         </form>     </div> 

main.js

$scope.validateproxy = function(startfield, endfield) {         console.log("calling validation...");         var isvalid = ($scope.attestordto[startfield]) <= ($scope.attestordto[endfield]);         $scope.addattesform[endfield].$setvalidity('daterange',isvalid);         $scope.addattesform.$setvalidity('daterange',isvalid);     }; 

remove readonly attribute. ng-change not fire on readonly input elements , model should changed via ui not javascript code.

try this:

<input type="text" class="form-control" id="attestorworker" required                                     ng-model="attestordto.attestorworker" name="attestorworker"                                     ng-change="validateproxy('attestorworker','proxyworker')"                                     ng-model-options="{updateon: 'blur'}"                                     ng-click="openattestorsearch()" />  <input type="text" class="form-control" id="proxyworker" required                                     ng-model="attestordto.proxyworker" name="proxyworker"                                     ng-model-options="{updateon: 'blur'}"                                     ng-click="openproxysearch()" ng-disabled="!attestordto.attestorworker" ng-change="validateproxy('attestorworker','proxyworker')" /> 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -