i have form has password filed , confirmpassword field. want compare password field against confirmpassword field. i'm having little of problem doing so, because have ng-show should display "passwords not match" error when password don't match @ moment messages shows.
<label class="control-label">password * <div class="row m-b-15"> <div class="col-md-12"> <input type="text" placeholder="password" name="password" required="" ng-model="user.password" class="form-control"/> </div> </div> <label class="control-label">re-enter password *</label> <div class="row m-b-15"> <div class="col-md-12"> <input type="text" placeholder="re-enter password" name="confirmpassword" required="" ng-model="user.confirmpassword" ka-compare-to="user.password" class="form-control"/> <div ng-show="signupform.confirmpassword.$error" class="form-group has-error"> <label class="control-label">passwords not match</label> </div> </div> </div> </label> .directive('kacompareto', function(){ return { restrict: 'a', require: 'ngmodel', scope: { othermodelvalue: '=kacompareto' }, link: function(scope, element, attributes, ngmodel){ ngmodel.$validators.kacompareto = function(modelvalue){ return modelvalue === scope.othermodelvalue; }; scope.$watch("othermodelvalue", function() { ngmodel.$validate(); }); } } })
thanks in advance.
to make work should change ng-show condition signupform.confirmpassword.$error
signupform.confirmpassword.$error.kacompareto
to achieve same behaviour, can use angularjs "ng-pattern" attribute instead of creating custom directive. imho better solution, because returns error if "confirmpassword" not empty:
<input type="text" placeholder="re-enter password" name="confirmpassword" required="" ng-pattern="user.password" ng-model="user.confirmpassword" class="form-control"/> <div ng-show="signupform.confirmpassword.$error.pattern" class="form-group has-error"> <label class="control-label">passwords not match</label> </div>
Comments
Post a Comment