Before I actually go ahead and open a PR, I wanted to check here to see if this approach would be valuable to the codebase.
Problem Overview:
We’re currently using the multiselect component to categorise content, with a fairly deep tree structure. Users need to select the leaf node at the end of the tree to categorise a page. Ideally, we’d like to display the paths like this:
"text": leaf
"info": branch 1 -> branch 2 -> branch 3
The issue arises when users search for “branch 3.” They get zero results because only the "text"
field is searchable. Currently, the only workaround is to display the entire path within the text
field, but this results in excessively long tags, which is not ideal.
Current Solution:
I’ve modified the code in PicklistInput.vue to optionally allow searching within the info
field as well.
filteredOptions() {
// min length for the search to kick in
if (this.query.length < (this.search.min ?? 0)) {
return;
}
if (this.search.includeInfoField) {
// Check both the text and info field for matches
let results = this.$helper.array.search(this.options, this.query, { field: "text" });
results = results.concat(this.$helper.array.search(this.options, this.query, { field: "info" }));
// Remove duplicates
results = results.filter((item, index, self) =>
index === self.findIndex((t) => t === item)
);
return results;
}
return this.$helper.array.search(this.options, this.query, {
field: "text"
});
},
and also highlighting the info text within choices():
info: this.search.includeInfoField ? this.highlight(option.info) : option.info
This way, users can enable the includeInfoField
flag in their configuration:
fields:
category:
label: Category
type: multiselect
search:
includeInfoField: true
Would it make sense to open a PR for this change as a first approach? Or is this (or a similar approach) unlikely to be merged into the codebase?