A platform for community discussion. Free, open, simple.
DEV: Fix category-selector's searching (#24023)
Bianca Nenciua6b570681b60
diff --git a/app/assets/javascripts/select-kit/addon/components/category-selector.js b/app/assets/javascripts/select-kit/addon/components/category-selector.jsindex cb90d629d82..a2fc25223af 100644--- a/app/assets/javascripts/select-kit/addon/components/category-selector.js+++ b/app/assets/javascripts/select-kit/addon/components/category-selector.js@@ -54,20 +54,27 @@ export default MultiSelectComponent.extend({},async search(filter) {- return this.siteSettings.lazy_load_categories- ? await Category.asyncSearch(filter, {- includeUncategorized:- this.attrs.options?.allowUncategorized !== undefined- ? this.attrs.options.allowUncategorized- : this.selectKit.options.allowUncategorized,- selectCategoryIds: this.categories- ? this.categories.map((x) => x.id)- : null,- rejectCategoryIds: this.blockedCategories- ? this.blockedCategories.map((x) => x.id)- : null,- })- : this._super(filter);+ if (!this.siteSettings.lazy_load_categories) {+ return this._super(filter);+ }++ const rejectCategoryIds = new Set();+ // Reject selected options+ if (this.categories) {+ this.categories.forEach((c) => rejectCategoryIds.add(c.id));+ }+ // Reject blocked categories+ if (this.blockedCategories) {+ this.blockedCategories.forEach((c) => rejectCategoryIds.add(c.id));+ }++ return await Category.asyncSearch(filter, {+ includeUncategorized:+ this.attrs.options?.allowUncategorized !== undefined+ ? this.attrs.options.allowUncategorized+ : this.selectKit.options.allowUncategorized,+ rejectCategoryIds: Array.from(rejectCategoryIds),+ });},select(value, item) {