From 311197fbce39ca5b028f471f49b611487397f7c3 Mon Sep 17 00:00:00 2001 From: Vadim Sikora Date: Fri, 16 Aug 2024 18:07:30 +0200 Subject: [PATCH] fix: Prevent datetimeshortcuts from rendering multiple times (#129) This was happening because scripts injected inside `$(document).ready(...)` would delay onload event and django's DateTimeShortcuts script attaches an event handler to `load` event to initialize the widgets. What would happen is our own initialization would run first and the one coming from django second resulting in duplicate widget. This change ensures our initialization happens last. See #128 --- rangefilter/templates/rangefilter/date_filter.html | 2 +- rangefilter/templates/rangefilter/date_filter_4_0.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rangefilter/templates/rangefilter/date_filter.html b/rangefilter/templates/rangefilter/date_filter.html index 502f21a..f1382cc 100644 --- a/rangefilter/templates/rangefilter/date_filter.html +++ b/rangefilter/templates/rangefilter/date_filter.html @@ -131,7 +131,7 @@ }); } - django.jQuery('document').ready(function () { + django.jQuery(window).on('load', function () { if (!('DateTimeShortcuts' in window)) { var promiseList = []; diff --git a/rangefilter/templates/rangefilter/date_filter_4_0.html b/rangefilter/templates/rangefilter/date_filter_4_0.html index 2e6a62c..9963b5f 100644 --- a/rangefilter/templates/rangefilter/date_filter_4_0.html +++ b/rangefilter/templates/rangefilter/date_filter_4_0.html @@ -127,7 +127,7 @@

{{ title }}

}); } - django.jQuery('document').ready(function () { + django.jQuery(window).on('load', function () { if (!('DateTimeShortcuts' in window)) { var promiseList = [];