Skip to content

Commit

Permalink
Run select2('destroy') inside the loop to ensure it attempts to destr… (
Browse files Browse the repository at this point in the history
#321)

* Run select2('destroy') inside the loop to ensure it attempts to destroy the element only if it's present in the DOM

* Remove new line
  • Loading branch information
andrew-mykhalchuk authored Jul 12, 2024
1 parent 9c26631 commit 203a528
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/assets/javascripts/spree/backend/spree-select2.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// we need to delete select2 instances before document is saved to cache
// https://stackoverflow.com/questions/36497723/select2-with-ajax-gets-initialized-several-times-with-rails-turbolinks-events
document.addEventListener("turbo:before-cache", function() {
$('select.select2').select2('destroy')
$('select.select2-clear').select2('destroy')
$('select.select2, select.select2-clear').each(function() {
$(this).select2('destroy')
})
})

document.addEventListener("spree:load", function() {
Expand Down

0 comments on commit 203a528

Please sign in to comment.