Bug 29500: Flatpickr - accept original date in the past and not others

Bug 29241 was supposed to fix this but it didn't properly.
We are accepting other dates in the past when we should only accept the
original one (the one from the DB) AND dates in future.

Test plan:
Retry test plan for 29241 and confirm that you cannot set manually another
date in the past.

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Jonathan Druart 2021-11-17 11:22:57 +01:00
parent 4f5670c889
commit 6cc3e618d8
1 changed files with 14 additions and 2 deletions

View File

@ -90,8 +90,20 @@
let options = {};
if( $(this).data("flatpickr-futuredate") === true ) {
options['minDate'] = new Date().fp_incr(1);
options['allowInvalidPreload'] = true;
let original_date = $(this).val();
if ( original_date ) {
original_date = Date_from_syspref( original_date ).getTime();
let tomorrow = new Date().fp_incr(1).getTime();
options['enable'] = [function(date){
date = date.getTime();
if ( date == original_date ) return true;
if ( date >= tomorrow) return true;
}];
}
else {
options['minDate'] = new Date().fp_incr(1);
}
}
if( $(this).data("flatpickr-pastinclusive") === true ) {
options['maxDate'] = "today";