From a98137bb572dc632de9e9d21042bca50049a7811 Mon Sep 17 00:00:00 2001 From: Giga Chubinidze Date: Thu, 3 Aug 2023 11:58:34 +0400 Subject: [PATCH] Date range in filters allows start date to be after end date [SCI-8796] --- .../javascripts/sitewide/date_time_picker.js | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/sitewide/date_time_picker.js b/app/assets/javascripts/sitewide/date_time_picker.js index 0e896a3c2..34a2bb656 100644 --- a/app/assets/javascripts/sitewide/date_time_picker.js +++ b/app/assets/javascripts/sitewide/date_time_picker.js @@ -6,7 +6,26 @@ ev.stopPropagation(); let dt = $(this); - let options = { ignoreReadonly: true }; + let selectedDate = {}; + + $('.calendar-input').slice(0, 2).each(function(index, element) { + if ($(element).val().length > 0 ) { + selectedDate.index = index; + selectedDate.date = $(element).val(); + } + }); + + let options = { + ignoreReadonly: true + }; + + if (selectedDate.date) { + if (selectedDate.index == 0) { + options.minDate = new Date(selectedDate.date); + } else if (selectedDate.index == 1) { + options.maxDate = new Date(selectedDate.date); + } + } if (dt.data('DateTimePicker')) { dt.data('DateTimePicker').destroy();