Skip to content

Commit

Permalink
Reset ckeditor/datepicker/selectpicker state before htmx saves history
Browse files Browse the repository at this point in the 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).
  • Loading branch information
sunnavy committed Apr 2, 2024
1 parent ddfb255 commit f52a076
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions share/static/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down

0 comments on commit f52a076

Please sign in to comment.