在angularjs中验证确认密码时禁用提交

时间:2014-07-18 08:21:45

标签: javascript angularjs

我想在验证确认密码时禁用提交按钮。我遵循这个模型:

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>

但问题是它没有检查密码字段,当提交按钮启用时,我再次输入密码字段另一个不同的值确认密码和提交按钮仍然启用。

非常感谢

2 个答案:

答案 0 :(得分:3)

我把你的小提琴分开了。结帐http://jsfiddle.net/dhavalcengg/ERX54

希望这会有所帮助。

答案 1 :(得分:0)

我会这样

OUTPUT VARCHAR(500);

BEGIN 

    FOR supplerTable IN (SELECT R_NAME, N_NAME
    FROM SUPPLIER join NATION on S_NATIONKEY = N_NATIONKEY
    join REGION on N_REGIONKEY = R_REGIONKEY
    GROUP BY R_NAME, N_NAME
    HAVING COUNT (S_NATIONKEY) > X)

DBMS_OUTPUT.PUT_LINE ('HELLO');

LOOP

DBMS_OUTPUT.PUT_LINE (supplerTable.R_NAME || supplerTable.N_NAME);

END LOOP;

END numOfSupplier;
/