From 4eee85709c4f215c2bc72bc480291b2d1c08007b Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Fri, 3 May 2024 14:07:25 +0000 Subject: [PATCH] Bug 36774: Remove wrapper if already exists Signed-off-by: David Nind Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer (cherry picked from commit c6e2995d278df289065a32f19af7ca9b9226d3ea) Signed-off-by: Fridolin Somers --- koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc index 842422ab37..e82f5d1298 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc @@ -48,17 +48,21 @@ "firstDayOfWeek": calendarFirstDayOfWeek }, onReady: function( selectedDates, dateStr, instance ){ + + /* When onReady is triggered, remove any existing "clear date" link */ + $(instance.input).parent().find('.flatpickr_wrapper_' + instance.input.id).remove(); + /* When flatpickr instance is created, automatically append a "clear date" link */ $(instance.input).find('~input.flatpickr:first') /* Add a wrapper element so that we can prevent the clear button from wrapping */ - .wrap("") + .wrap("") .attr("autocomplete", "off") .after( $("") .attr("href","#") .addClass("clear_date") .on("click", function(e){ e.preventDefault(); - instance.clear(); + instance.input.flatpickr().clear(); }) .addClass("fa fa-fw fa-times") .attr("aria-hidden", true) -- 2.39.5