表单允许即使密码不匹配也可以提交-AngularJS

时间:2019-11-25 12:49:03

标签: javascript angularjs forms angularjs-directive

问题描述:

  • “确认密码”字段开始禁用(变灰)。仅在“密码”字段中输入正确的密码格式(至少6个字符,包括至少一个数字)后才能启用。

  • 请先在“密码”字段中输入密码,然后在“确认密码”中输入密码即可。引发验证错误,仅在密码匹配时才允许提交,等等。

  • 但是,此后,只要保持密码格式,它就允许用户在“密码”字段中输入所需内容。不抛出验证错误,允许用户提交。之后,用户可以使用在“密码”字段中输入的密码登录

这是代码。我不能透露太多,因为它是别人的,但我很确定该bug位于此HTML中。 在启用提交之前,如何确保密码匹配?

<div class="row">
  <div class="form-group col-md-6" ng-if="!vm.isEdit">
    <label class="required_input_field" for="password">{{'LABEL_PASSWORD'}}</label>
    <input  type="password"
            autocomplete="new-password"
            id="password"
            name="userpassword"
            class="form-control"
            formnovalidate
            ng-pattern="/(?=^[^\s]{6,20}$)(?=.*\d)(?=.*[a-zA-Z])/"
            ng-cut="$event.preventDefault()"
            ng-copy="$event.preventDefault()"
            ng-paste="$event.preventDefault()"
            ng-model="vm.user.password"
            ng-pattern="{{vm.confirmpassword}}"
            ng-minlength="6"
            ng-maxlength="50"
            ng-required="!vm.isEdit" />
    <div class="error" ng-show="addUserForm.userpassword.$dirty && addUserForm.userpassword.$invalid">
      <div ng-messages="addUserForm.userpassword.$error">
        <div class="validation-text" ng-message="required">{{'ERROR_REQUIRED'}}</div>
        <div class="validation-text" ng-message="minlength">{{'ERROR_LENGTH_PASSWORD'}}</div>
        <div class="validation-text" ng-message="maxlength">{{'ERROR_LENGTH_PASSWORD'}}</div>
        <div class="validation-text" ng-message="pattern">{{'ERROR_PATTERN_PASSWORD'}}</div>
      </div>
    </div>
  </div>
  <div class="form-group col-md-6" ng-if="!vm.isEdit">
    <label class="required_input_field" for="confirmpassword">{{'LABEL_CONFIRM_PASSWORD'}}</label>
    <input  autocomplete="off"
            type="password"
            id="confirmpassword"
            name="confirmpassword"
            class="form-control"
            ui-validate="'$value==vm.user.password'"
            ng-disabled="addUserForm.userpassword.$invalid"
            ng-cut="$event.preventDefault()"
            ng-copy="$event.preventDefault()"
            ng-paste="$event.preventDefault()"
            ng-model="vm.confirmpassword"
            ng-pattern="{{vm.user.Password}}"
            ng-required="!vm.isEdit " />
    <div class="error" ng-show="addUserForm.confirmpassword.$dirty && addUserForm.confirmpassword.$invalid">
      <div ng-messages="addUserForm.confirmpassword.$error">
        <div class="validation-text" ng-message="required">{{'ERROR_REQUIRED'}}</div>
        <div class="validation-text" ng-message="pattern">{{'ERROR_PASSWORD_MISMATCH'}}</div>
        <span class="validation-text" ng-message="validator">
          {{'ERROR_PASSWORD_MISMATCH'}}
        </span>
      </div>
    </div>
  </div>
  </div>

0 个答案:

没有答案