我正在使用jQuery validation plugin来验证我的密码设置表单。
我的代码存在以下问题。
我使用点击事件提交表单,如下所示:
$('#updatePasswordButton').click(function () {
postSettings();
});
$("#PasswordForm").validate({
rules: {
PASSWORD1: {
required: true,
},
PASSWORD2: {
equalTo: "#PASSWORD1"
}
},
messages: {
PASSWORD2: "The passwords do not match"
},
//TODO yet to highlight the DOM element which has validation error
highlight: function(element, errorClass) {
$(element).closest('.form-control').addClass('has-error');
},
unhighlight: function(element, errorClass) {
$(element).closest(".form-control").removeClass("has-error");
},
submitHandler: function(form) {
console.log("submit handle");
return false;
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.15.0/jquery.validate.min.js"></script>
<form name="PasswordForm" id="PasswordForm" method="post">
<td id="updatePassword">
<a id="updatePasswordButton" class="btn btn-sm btn-bitbucket" name="setPassword">
<i id="updatePass" class="demo-icon icon-lock"> </i> UPDATE PASSWORD</a>
</td>
</form>