2014-07-18 2 views
0

비밀번호 확인을 확인할 때 제출 버튼을 비활성화하고 싶습니다.anglejs에서 비밀번호 확인 확인시 제출 사용 안함

JSFIDDLE

AngularJS와 :

var app = angular.module('myapp', ['UserValidation']); 

    angular.module('UserValidation', []).directive('validPasswordC', function() { 
     return { 
      require: 'ngModel', 
      link: function (scope, elm, attrs, ctrl) { 
       ctrl.$parsers.unshift(function (viewValue, $scope) { 
        var noMatch = viewValue != scope.myForm.password.$viewValue 
        ctrl.$setValidity('noMatch', !noMatch) 
       }) 
      } 
     } 
    }) 

보기 :

<div ng-app="myapp"> 
     <form name="myForm"> 



      <label for="password">Password</label> 
      <input type="password" id="password" name="password" ng-model="formData.password" ng-minlength="8" ng-maxlength="20" ng-pattern="/(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z])/" required /> 
     <span ng-show="myForm.password.$error.required && myForm.password.$dirty">required</span> 
     <span ng-show="!myForm.password.$error.required && (myForm.password.$error.minlength || myForm.password.$error.maxlength) && myForm.password.$dirty">Passwords must be between 8 and 20 characters.</span> 
     <span ng-show="!myForm.password.$error.required && !myForm.password.$error.minlength && !myForm.password.$error.maxlength && myForm.password.$error.pattern && myForm.password.$dirty">Must contain one lower &amp; uppercase letter, and one non-alpha character (a number or a symbol.)</span> 
      <br /> 


      <label for="password_c">Confirm Password</label> 
      <input type="password" id="password_c" name="password_c" ng-model="formData.password_c" valid-password-c required /> 
     <span ng-show="myForm.password_c.$error.required && myForm.password_c.$dirty">Please confirm your password.</span> 
     <span ng-show="!myForm.password_c.$error.required && myForm.password_c.$error.noMatch && myForm.password.$dirty">Passwords do not match.</span> 
      <br /> 

     <button type="submit" class="btn" ng-disabled="!myForm.$valid">Submit</button> 
     </form> 
     </div> 

그러나 문제는 그것은 암호 필드를 확인하지 않는다는 것입니다, 때 제출 나는이 모델을 따라 버튼 활성화, 다시 입력 비밀 번호 필드 다른 다른 값 비밀 번호와 제출 버튼을 확인 여전히 사용 가능합니다.

감사합니다 내가 당신의 바이올린 갈래의 한

답변

관련 문제