尝试使用 和 进行密码password
更改new_password
页面confirm_password
。
我有两个问题:
- 密码验证器强度字段是由所有三个密码字段的输入触发的,而我只希望它应用于
new_password
用户选择新密码的字段。 - 验证不会附加文本错误消息,它会更改要检查或未检查的类,因此会显示叉号或勾号,但不会向用户显示字段验证失败的原因。
我正在使用 jQuery 1.8.3,jquery.validate
来自jquery.validate.password
bassistance。
任何想法都非常感激。
下面的 HTML 和 jQuery:
<form novalidate="novalidate" method="POST" action="/frontend_dev.php/profile/change-password" name="change_account_data_form" id="change_account_password_form">
<table cellspacing="0">
<tbody><tr>
<td colspan="3">
</td>
</tr>
<tr>
<td><label for="current_password">Current password:</label></td>
<td><input style="display: none;" name="change_password[password]" id="password" class="text" type="password"><input class="text" type="text"></td>
<td></td>
</tr>
<tr>
<td><label for="password">New password:</label></td>
<td><input style="display: none;" name="change_password[new_password]" id="new_password" class="text password" type="password"><input class="text password" type="text"></td>
<td><div class="password-meter">
<div class="password-meter-message"> </div>
<div class="password-meter-bg">
<div class="password-meter-bar"></div>
</div>
</div>
</td>
</tr>
<tr>
<td><label for="password_confirm">Confirm password:</label></td>
<td><input style="display: none;" name="change_password[password_confirm]" id="password_confirm" class="text" type="password"><input class="text" type="text"></td>
<td></td>
</tr>
</tbody></table>
<input name="change_password[id]" value="2" id="change_password_id" type="hidden"><input name="change_password[_csrf_token]" value="66dbd4dc532ad1c9dd668e5e86235136" id="change_password__csrf_token" type="hidden">
<div class="submitBlock">
<input class="buttonSubmit" value="" type="submit">
</div>
</form>
查询:
$(document).ready(function() {
// validate signup form on keyup and submit
var validator = $("#change_account_password_form").validate({
debug:true,
errorClass: 'jqueryError',
rules: {
password: {
required: true,
minlength: 8
},
new_password: {
password: "#new_password",
minlength: 8
},
password_confirm: {
required: true,
equalTo: "#new_password"
}
},
messages: {
password: {
required: "Enter your current password",
minlength: jQuery.format("Enter at least {0} characters")
},
new_password: {
required: "Enter your new password",
minlength: jQuery.format("Enter at least {0} characters")
},
password_confirm: {
required: "Repeat your password",
minlength: jQuery.format("Enter at least {0} characters"),
equalTo: "Enter the same password as above"
}
},
// the errorPlacement has to take the table layout into account
errorPlacement: function(error, element) {
error.prependTo( element.parent().next() );
},
// specifying a submitHandler prevents the default submit, good for the demo
submitHandler: function() {
alert("submitted!");
},
// set this class to error-labels to indicate valid fields
success: function(label) {
// set as text for IE
label.html(" ").addClass("jqueryChecked");
}
});
});