From f2b57fec9b3b59151b8b75b09d4945982eed7614 Mon Sep 17 00:00:00 2001 From: m <m> Date: Fri, 10 Aug 2018 13:26:03 +0200 Subject: [PATCH] correct #361 --- js/app/framadatepicker.js | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/js/app/framadatepicker.js b/js/app/framadatepicker.js index 10847c63..5a57426e 100644 --- a/js/app/framadatepicker.js +++ b/js/app/framadatepicker.js @@ -16,7 +16,11 @@ * Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft) */ $(document).ready(function () { + + let datepickerLoaded = false; + var init_datepicker = function () { + $('.input-group.date').datepicker({ format: window.date_formats.DATEPICKER || "dd/mm/yyyy", todayBtn: "linked", @@ -25,28 +29,43 @@ $(document).ready(function () { language: lang, todayHighlight: true, beforeShowDay: function (date) { + + if (!datepickerLoaded) { + return true; + } + + // Retrieve selected dates from text fields + var selected_days = []; - $('#selected-days').find('input[id^="day"]').each(function () { - if ($(this).val() != '') { - selected_days.push($(this).val()); - } + + $('.input-group.date').each(function () { + selected_days.push($(this).datepicker("getDate").getTime()); }); - + + // Disable selected dates in DatePicker for (var i = 0; i < selected_days.length; i++) { - var selected_date = selected_days[i].split('/'); - - if (date.getFullYear() == selected_date[2] && (date.getMonth() + 1) == selected_date[1] && date.getDate() == selected_date[0]) { + + if (date.getTime() === selected_days[i]) { return { classes: 'disabled selected' }; } + } + + return true; + } }); + + + datepickerLoaded = true; + }; - + + $(document).on('click', '.input-group.date .input-group-addon, .input-group.date input', function () { // Re-init datepicker config before displaying init_datepicker(); -- GitLab