Commit afd9e7a7 authored by Robert Lyon's avatar Robert Lyon

Bug 1831689: Adjusting how we update dates on the the view access page

There was a problem where we set up fields with empty date and then
try to add a date to it

Instead we should set up the datepicker with the date so that works
out what type of date it is first so then can handle it correctly

Note: if trying to use format DD/MM/YYYY it will complain that it is a
non-compatible date

behatnotneeded

Change-Id: I401e0812dc2c4189b715033fcf7b745c52425b05
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 452f2acd
......@@ -333,7 +333,12 @@ function pieform_element_calendar_convert_to_epoch($date) {
// (See http://php.net/manual/en/function.strtotime.php#refsect1-function.strtotime-notes)
$dateformat = get_string('pieform_calendar_dateformat', 'langconfig');
if (preg_match('/%[ed].*%[m].*%[yY]/', $dateformat)) {
$value = strtotime(preg_replace('/[^0-9]/', '.', $date));
$timesuffix = preg_match('/(am|pm)$/i', $date, $match);
$fixdate = preg_replace('/[^0-9]/', '.', $date);
if ($timesuffix) {
$fixdate = preg_replace('/[^\d](\.+)$/', $match[1], $fixdate);
}
$value = strtotime($fixdate);
}
// If that didn't work, then just try doing strtotime on the plain value
......
......@@ -159,43 +159,39 @@ jQuery(function($) {
function setDatePicker(target) {
var loc = '{{strstr(current_language(), '.', true)}}'; // Get current langauge to use for locale
target.datetimepicker({
useCurrent: false,
format: "{{str(tag='pieform_calendar_dateformat' section='langconfig')|pieform_element_calendar_convert_dateformat}} {{str(tag='pieform_calendar_timeformat' section='langconfig')|pieform_element_calendar_convert_timeformat}}",
locale: loc,
buttons: {
showClear: true,
showToday: true,
},
tooltips: {{$datepickertooltips|safe}},
icons: {
time: "icon icon-clock-o",
date: "icon icon-calendar",
up: "icon icon-arrow-up",
down: "icon icon-arrow-down",
previous: "icon icon-chevron-left",
next: "icon icon-chevron-right",
close: "icon icon-times",
clear: "icon icon-trash",
today: "icon icon-crosshairs",
},
});
target.on('hide.datetimepicker', function(selectedDate) {
if (selectedDate !== "") {
formchangemanager.setFormStateById('{{$formname}}', FORM_CHANGED);
}
});
// ugly fix for open issue in tempusdominus bootstrap lib not getting the value from html tag
// https://github.com/tempusdominus/bootstrap-4/issues/126
target.each(function() {
// ugly fix for open issue in tempusdominus bootstrap lib not getting the value from html tag
// https://github.com/tempusdominus/bootstrap-4/issues/126
var value = $(this).attr('value');
value = value == '' ? null : value;
$(this).datetimepicker({
format: "{{str(tag='pieform_calendar_dateformat' section='langconfig')|pieform_element_calendar_convert_dateformat}} {{str(tag='pieform_calendar_timeformat' section='langconfig')|pieform_element_calendar_convert_timeformat}}",
date: value
date: value,
useCurrent: false,
locale: loc,
buttons: {
showClear: true,
showToday: true,
},
tooltips: {{$datepickertooltips|safe}},
icons: {
time: "icon icon-clock-o",
date: "icon icon-calendar",
up: "icon icon-arrow-up",
down: "icon icon-arrow-down",
previous: "icon icon-chevron-left",
next: "icon icon-chevron-right",
close: "icon icon-times",
clear: "icon icon-trash",
today: "icon icon-crosshairs",
},
});
$(this).val(value);
$(this).on('hide.datetimepicker', function(selectedDate) {
if (selectedDate !== "") {
formchangemanager.setFormStateById('{{$formname}}', FORM_CHANGED);
}
});
});
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment