javascript - Angularjs server side validation of multiple parameters -


i have made attempt create custom validation directive validate 2 items simultaneously @ server side.

i have 2 values regnumber , regdate have validated along each other. when user enters both of them correctly,they validate. but, if 1 of them entered incorrectly, both have invalidated.

to accomplish goal, have written following directive base on post.

everything working fine except when enter both regnumber , regdate incorrectly. then, if change them both correct values, still invalidated.

by "everythin working fine" mean when enter invalid value regnumber , valid value regdate, , change regnumber valid value, works fine , vice versa(first regdate , regnumber).

i think $setvalidatity set latest input has been changed , not both of them if guess true, don't know how solve it. :d

directive:

 osiapp.directive('uniqueorder', function ($http, $rootscope) {         var toid;         return {             restrict: 'a',             require: 'ngmodel',             link: function (scope, elem, attr, ctrl) {                 scope.$watch(attr.ngmodel, function (value) {                     if (scope.osirequest.regdate) {                         ctrl.$setvalidity('uniqueorder', true);                         if (toid) cleartimeout(toid);                         toid = settimeout(function () {                             $http({                                 method: 'get',                                 url: $rootscope.baseaddress + '/validateorderregistrationnumber/get',                                 params: {                                     orderregistrationdate: scope.osirequest.regdate ,                                     orderregistrationnumber: scope.osirequest.regnumber                                  }                             }).success(function (isvalid) {                                 ctrl.$setvalidity('uniqueorder', isvalid);                             });                         }, 200);                     }                 });             }         }     }); 

html:

    <div class="form-group" ng-class="myform.regnumber.$error.uniqueorder ||                 myform.regdate.$error.uniqueorder ? 'has-error' : ''">     <input class="form-control"           name="regnumber" ng-model="osirequest.regnumber" unique-order>     </div>        <div class="form-group" ng-class="myform.regnumber.$error.uniqueorder ||                 myform.regdate.$error.uniqueorder ? 'has-error' : ''">     <input class="form-control"           name="regdate" ng-model="osirequest.regdate " unique-order>     </div> 

as mentioned @nicolasmoise have able access both model in directive, few ways achieve :

  1. adding both ng-model osirequest.regdate & osirequest.regnumber directive attributes unique-order. check "scope" parameter directive.

  2. access parent controller scope directive using $parent ( not ideal )


Comments