password
、new_password
およびでパスワード変更ページを実行しようとしていますconfirm_password
。
2 つの問題があります。
- パスワードバリデータの強度フィールドは、3 つのパスワードフィールドすべてへの入力によってトリガーされます
new_password
が、ユーザーが新しいパスワードを選択するフィールドにのみ適用したいと考えています。 - 検証はテキストエラーメッセージを追加しません。クラスをチェックまたはチェック解除するように変更するため、十字または目盛りが表示されますが、フィールドが検証に失敗した理由を示すメッセージはユーザーに表示されません。
私はjQuery 1.8.3を使用してjquery.validate
いjquery.validate.password
ます。
どんなアイデアもありがたく受け取った。
以下の 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>
Jクエリ:
$(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");
}
});
});