Koha/koha-tmpl/intranet-tmpl/prog/js/categories.js
Owen Leonard 1bd10a4a2e Bug 28928: Minor follow-ups to Bug 28376 - Flatpickr introduction
This patch corrects three errors in the original Flatpickr introduction
patch:

- Missing document.ready() in borrowers_stats.tt.
- Redundant calendarFirstDayOfWeek setting in caregories.js
- Missing preventDefault() in calendar.inc

The first two issues don't appear to cause any malfunction but are best
practices. The third issue can cause the page to scroll unexpectedly.

To reproduce this bug, go to (for instance) Administration -> Patron
categories -> New category.

 - If necessary, narrow the height of your browser window so that there
   is a vertical scrollbar.
 - Scroll down the page so that the "Until date" field is at the top.
 - Click the "X" next to the field.
 - The page will scroll to the top.

Apply the patch and test again. The page jump should not occur.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2021-09-01 15:46:01 +02:00

103 lines
2.9 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"
}, ],
"aaSorting": [
[1, "asc"]
],
"sPaginationType": "full",
"exportColumns": [0,1,2,3,4,5,6,7,8,9,10,11,12],
}, columns_settings);
$("#enrolmentperioddate").flatpickr({
minDate: new Date().fp_incr(1)
});
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
},
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.")
}
}
});
});