Owen Leonard
f471ed3903
This patch updates the patron category entry form so that it is validated using the staff client's globally-included form validation plugin. This patch also moves the page's JavaScript into a separate file. To test, apply the patch and go to Administration -> Patron categories. - Create a new category. Try to submit the form with the following fields empty: - Category code - Description - Both enrollment period fields - Category type - Try to enter data in the category code field which contains characters other than letters, numbers, hyphens, or underscores. - Try to enter non-numeric data in the following fields: - Enrollment period in months - Age required - Upper age limit - Enrollment fee - Hold fee - Try to submit the form with both enrollment period fields filled. Followed test plan, works as expected. Signed-off-by: Marc Véron <veron@veron.ch> Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
97 lines
No EOL
2.6 KiB
JavaScript
97 lines
No EOL
2.6 KiB
JavaScript
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;
|
|
}
|
|
}, MSG_CATEGORYCODE_CHARS
|
|
);
|
|
|
|
jQuery.validator.addMethod( "enrollment_period", function(){
|
|
enrolmentperiod = $("#enrolmentperiod").val();
|
|
enrolmentperioddate = $("#enrolmentperioddate").val();
|
|
if ( $("#enrolmentperiod").val() !== "" && $("#enrolmentperioddate").val() !== "" ) {
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
}, MSG_ONE_ENROLLMENTPERIOD
|
|
);
|
|
|
|
|
|
$(document).ready(function() {
|
|
$("#table_categorie").dataTable($.extend(true, {}, dataTablesDefaults, {
|
|
"aoColumnDefs": [{
|
|
"aTargets": [-1, -2],
|
|
"bSortable": false,
|
|
"bSearchable": false
|
|
}, {
|
|
"aTargets": [3, 4, 5],
|
|
"sType": "natural"
|
|
}, ],
|
|
"aaSorting": [
|
|
[1, "asc"]
|
|
],
|
|
"sPaginationType": "four_button"
|
|
}));
|
|
|
|
$("#enrolmentperioddate").datepicker({
|
|
minDate: 1
|
|
}); // Require that "until date" be in the future
|
|
|
|
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() === "";
|
|
},
|
|
number: true,
|
|
enrollment_period: true
|
|
},
|
|
enrolmentperioddate: {
|
|
required: function(element){
|
|
return $("#enrolmentperiod").val() === "";
|
|
},
|
|
enrollment_period: true
|
|
},
|
|
dateofbirthrequired: {
|
|
number: true
|
|
},
|
|
upperagelimit: {
|
|
number: true
|
|
},
|
|
enrolmentfee: {
|
|
number: true
|
|
},
|
|
reservefee: {
|
|
number: true
|
|
},
|
|
category_type: {
|
|
required: true
|
|
}
|
|
},
|
|
messages: {
|
|
enrolmentperiod: {
|
|
required: MSG_ONE_ENROLLMENTPERIOD
|
|
},
|
|
enrolmentperioddate: {
|
|
required: MSG_ONE_ENROLLMENTPERIOD
|
|
}
|
|
}
|
|
|
|
});
|
|
}); |