Koha/koha-tmpl/intranet-tmpl/prog/js/categories.js
Jonathan Druart 79396ae625
Bug 30864: Add validation to password_expiry_days
When creating a patron category or editing an existing one, there is no validation for the "Password expiration" field.

If letters or other characters are entered, there is no error message and if not a number whatever is entered is not saved.

To test:
1. Go to Administration > Patrons and circulation > Patron categories.
2. Add a new patron category (or edit an existing category).
3. For the "Password expiration" field, enter letters or characters such as L$%.
=> Note that you are prompted to "Please enter only digits"

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
2022-06-06 13:49:00 -03:00

99 lines
2.8 KiB
JavaScript

/* global __ */
jQuery.validator.addMethod( "letters_numbers", function(value,element){
var patt = /^[a-zA-Z0-9\-_]+$/g;
if (patt.test(element.value)) {
return true;
} else {
return false;
}
}, __("Category code can only contain the following characters: letters, numbers, - and _.")
);
jQuery.validator.addMethod( "enrollment_period", function(){
enrolmentperiod = $("#enrolmentperiod").val();
enrolmentperioddate = $("#enrolmentperioddate").val();
if ( $("#enrolmentperiod").val() !== "" && $("#enrolmentperioddate").val() !== "" ) {
return false;
} else {
return true;
}
}, __("Please choose an enrollment period in months OR by date.")
);
$(document).ready(function() {
KohaTable("patron_categories", {
"aoColumnDefs": [{
"aTargets": [-1],
"bSortable": false,
"bSearchable": false
}, {
"aTargets": [3, 4, 5],
"sType": "natural"
}, ],
"sPaginationType": "full",
"exportColumns": [0,1,2,3,4,5,6,7,8,9,10,11,12],
}, table_settings);
if ($("#branches option:selected").length < 1) {
$("#branches option:first").attr("selected", "selected");
}
$("#categorycode").on("blur",function(){
toUC(this);
});
$("#category_form").validate({
rules: {
categorycode: {
required: true,
letters_numbers: true
},
description: "required",
enrolmentperiod: {
required: function(element){
return $("#enrolmentperioddate").val() === "";
},
digits: true,
enrollment_period: true,
min: 1
},
enrolmentperioddate: {
required: function(element){
return $("#enrolmentperiod").val() === "";
},
enrollment_period: true
},
password_expiry_days: {
digits: true
},
dateofbirthrequired: {
digits: true
},
upperagelimit: {
digits: true
},
enrolmentfee: {
number: true
},
reservefee: {
number: true
},
category_type: {
required: true
},
min_password_length: {
digits: true
}
},
messages: {
enrolmentperiod: {
required: __("Please choose an enrollment period in months OR by date.")
},
enrolmentperioddate: {
required: __("Please choose an enrollment period in months OR by date.")
}
}
});
});