From 200a68386d80b9c58f2793a928a0d66f3ff1332f Mon Sep 17 00:00:00 2001 From: Ihsan Ullah Date: Thu, 15 May 2025 14:31:06 +0500 Subject: [PATCH 1/2] Calendar lock fixed, additional check added for start and end date --- .../riot/competitions/editor/_phases.tag | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/static/riot/competitions/editor/_phases.tag b/src/static/riot/competitions/editor/_phases.tag index ef82ff274..c611ede44 100644 --- a/src/static/riot/competitions/editor/_phases.tag +++ b/src/static/riot/competitions/editor/_phases.tag @@ -432,19 +432,16 @@ } } - // Create a new options object for the start date calendar by combining 'date_options' - // with an additional option to link the end date calendar. This ensures that the start date - // cannot be after the selected end date. - var start_options = Object.assign({}, date_options, {endCalendar: self.refs.calendar_end_date}) + // Create a new options object for the start date calendar using 'date_options' + var start_options = Object.assign({}, date_options) - // Similarly, create a new options object for the end date calendar, linking it to the start date. - // This ensures that the end date cannot be before the selected start date. - var end_options = Object.assign({}, date_options, {startCalendar: self.refs.calendar_start_date}) + // Create a new options object for the end date calendar using 'date_options' + var end_options = Object.assign({}, date_options) - // Initialize the start date calendar using the options defined above, including the end date limitation. + // Initialize the start date calendar using the options defined above $(self.refs.calendar_start_date).calendar(start_options) - // Initialize the end date calendar using the options defined above, which includes the start date limitation. + // Initialize the end date calendar using the options defined above $(self.refs.calendar_end_date).calendar(end_options) @@ -806,6 +803,12 @@ data.end_time = "00:00" } data.end = self.formatDateTo_Y_m_d_T_H_M_S(data.end_date + " " + data.end_time) + + // Check: start date must not be after end date + if (new Date(data.start) > new Date(data.end)) { + toastr.error("End date cannot be earlier than the start date. Please choose a valid date range.") + return + } }else{ // end date is set to null if it is not selected because it is optional in the form data.end = null From 93763667bfa581ff82bbd3894a68a74afafdde6a Mon Sep 17 00:00:00 2001 From: didayolo Date: Thu, 15 May 2025 12:02:53 +0200 Subject: [PATCH 2/2] Simplify code --- src/static/riot/competitions/editor/_phases.tag | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/static/riot/competitions/editor/_phases.tag b/src/static/riot/competitions/editor/_phases.tag index c611ede44..b55520e0d 100644 --- a/src/static/riot/competitions/editor/_phases.tag +++ b/src/static/riot/competitions/editor/_phases.tag @@ -433,18 +433,9 @@ } // Create a new options object for the start date calendar using 'date_options' - var start_options = Object.assign({}, date_options) - + $(self.refs.calendar_start_date).calendar(date_options) // Create a new options object for the end date calendar using 'date_options' - var end_options = Object.assign({}, date_options) - - // Initialize the start date calendar using the options defined above - $(self.refs.calendar_start_date).calendar(start_options) - - // Initialize the end date calendar using the options defined above - $(self.refs.calendar_end_date).calendar(end_options) - - + $(self.refs.calendar_end_date).calendar(date_options) // Initialize the start time calendar with the defined options. // This will create a time picker for the 'start time' field.