Bug 36774: Remove wrapper if already exists

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
(cherry picked from commit c6e2995d27)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Pedro Amorim 2024-05-03 14:07:25 +00:00 committed by Fridolin Somers
parent 465a41d7c1
commit 4eee85709c

View file

@ -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("<span class='flatpickr_wrapper'></span>")
.wrap("<span class='flatpickr_wrapper flatpickr_wrapper_"+instance.input.id+"'></span>")
.attr("autocomplete", "off")
.after( $("<a/>")
.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)