Commit afd9e7a7 authored by Robert Lyon's avatar Robert Lyon
Browse files

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: default avatarRobert Lyon <robertl@catalyst.net.nz>
parent 452f2acd
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -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
+27 −31
Original line number Diff line number Diff line
@@ -159,9 +159,15 @@ jQuery(function($) {

        function setDatePicker(target) {
            var loc = '{{strstr(current_language(), '.', true)}}'; // Get current langauge to use for locale
            target.datetimepicker({
                useCurrent: false,
            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,
                    useCurrent: false,
                    locale: loc,
                    buttons: {
                        showClear: true,
@@ -180,22 +186,12 @@ jQuery(function($) {
                        today: "icon icon-crosshairs",
                    },
                });

            target.on('hide.datetimepicker', function(selectedDate) {
                $(this).val(value);
                $(this).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() {
                var value = $(this).attr('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
                });
                $(this).val(value);
            });
        }