From f52a07631ee48f479757cdbb62fe0849927ff32e Mon Sep 17 00:00:00 2001 From: sunnavy Date: Mon, 1 Apr 2024 16:51:21 -0400 Subject: [PATCH] Reset ckeditor/datepicker/selectpicker state before htmx saves history When htmx loads history from cache(e.g. via browser's Back button), these elements will be fully re-initialized. Otherwise they wouldn't work, e.g. you would see 2 ckeditor panes(the new created pane works, the old one does not). --- share/static/js/util.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/share/static/js/util.js b/share/static/js/util.js index be3f715dd0f..6103b353045 100644 --- a/share/static/js/util.js +++ b/share/static/js/util.js @@ -768,6 +768,18 @@ jQuery(function() { } }); + document.body.addEventListener('htmx:beforeHistorySave', function(evt) { + evt.detail.historyElt.querySelector('#hx-boost-spinner').classList.add('d-none'); + evt.detail.historyElt.querySelectorAll('textarea.richtext').forEach(function(elt) { + CKEDITOR.instances[elt.name].destroy(); + }); + evt.detail.historyElt.querySelectorAll('.hasDatepicker').forEach(function(elt) { + elt.classList.remove('hasDatepicker'); + }); + + jQuery(evt.detail.historyElt).find('.selectpicker').selectpicker('destroy').addClass('selectpicker'); + }); + document.body.addEventListener('actionsChanged', function(evt) { if ( evt.detail.value ) { for ( const action of evt.detail.value ) {