Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Improve filter js.

Matthew Kennedye2345ae07b52
diff --git a/backend/app/assets/javascripts/spree/backend/admin.js b/backend/app/assets/javascripts/spree/backend/admin.js
index f6e91cbccb..43a16718f0 100644
--- a/backend/app/assets/javascripts/spree/backend/admin.js
+++ b/backend/app/assets/javascripts/spree/backend/admin.js
@@ -117,10 +117,12 @@ jQuery(function ($) {
}
}
- $('.js-filterable').each(function () {
+ // To appear in the filtered options, the elements id attribute must start with 'q_',
+ // and it must have the class'.js-filterable'.
+ $('[id^="q_"].js-filterable').each(function () {
var $this = $(this)
- if ($this.val() !== null && $this.val() !== '' && $this.val().length !== 0 && !$this.hasClass('flatpickr-alt-input') && !$this.hasClass('flatpickr-mobile')) {
+ if ($this.val() !== null && $this.val() !== '' && $this.val().length !== 0) {
var ransackValue, filter
var ransackFieldId = $this.attr('id')
var label = $('label[for="' + ransackFieldId + '"]')
@@ -134,10 +136,11 @@ jQuery(function ($) {
}
label = ransackField(label.text()) + ': ' + ransackValue
+
var cleanLabel = DOMPurify.sanitize(label)
filter = '<span class="js-filter badge badge-secondary" data-ransack-field="' + ransackFieldId + '">' + cleanLabel + '<i class="icon icon-cancel ml-2 js-delete-filter"></i></span>'
- $(".js-filters").append(filter).show()
+ $('.js-filters').append(filter).show()
}
})