2012-10-03 23:34:27 +02:00
|
|
|
$(function () {
|
2013-04-03 22:30:36 +02:00
|
|
|
// NB: this file is included on multiple pages. In each context,
|
|
|
|
// some of the jQuery selectors below will return empty lists.
|
|
|
|
|
|
|
|
$.validator.addMethod('password', function (value, element) {
|
2013-04-08 20:39:13 +02:00
|
|
|
return password_quality(value);
|
2013-04-03 22:30:36 +02:00
|
|
|
}, 'Password is weak.');
|
|
|
|
|
2013-04-03 20:33:25 +02:00
|
|
|
function highlight(class_to_add) {
|
|
|
|
// Set a class on the enclosing control group.
|
|
|
|
return function (element) {
|
|
|
|
$(element).closest('.control-group')
|
|
|
|
.removeClass('success error')
|
|
|
|
.addClass(class_to_add);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-10-03 23:43:25 +02:00
|
|
|
$('#registration').validate({
|
2013-04-03 22:30:36 +02:00
|
|
|
rules: {
|
|
|
|
id_password: 'password'
|
|
|
|
},
|
2012-10-03 23:43:25 +02:00
|
|
|
errorElement: "p",
|
|
|
|
errorPlacement: function (error, element) {
|
2013-04-03 20:33:25 +02:00
|
|
|
// NB: this is called at most once, when the error element
|
|
|
|
// is created.
|
|
|
|
error.insertAfter(element).addClass('help-inline');
|
2012-10-03 23:43:25 +02:00
|
|
|
},
|
2013-04-03 20:33:25 +02:00
|
|
|
highlight: highlight('error'),
|
|
|
|
unhighlight: highlight('success')
|
2012-10-03 23:43:25 +02:00
|
|
|
});
|
|
|
|
|
2013-04-08 20:39:13 +02:00
|
|
|
$('#id_password').on('change keyup', function () {
|
|
|
|
// Update the password strength bar even if we aren't validating
|
|
|
|
// the field yet.
|
|
|
|
password_quality($('#id_password').val(), $('#pw_strength .bar'));
|
2013-04-03 22:30:36 +02:00
|
|
|
});
|
|
|
|
|
2013-04-03 18:51:36 +02:00
|
|
|
$("#send_confirm").validate({
|
2012-10-03 23:43:25 +02:00
|
|
|
errorElement: "p",
|
|
|
|
errorPlacement: function (error, element) {
|
|
|
|
$('#errors').empty();
|
|
|
|
error.appendTo("#errors")
|
2012-10-04 17:05:34 +02:00
|
|
|
.addClass("text-error");
|
2012-10-03 23:43:25 +02:00
|
|
|
},
|
2013-04-03 19:08:11 +02:00
|
|
|
success: function () {
|
|
|
|
$('#errors').empty();
|
2012-10-04 17:05:34 +02:00
|
|
|
}
|
2012-09-25 22:58:59 +02:00
|
|
|
});
|
|
|
|
});
|