Skip to content

Commit

Permalink
Merge pull request #14786 from primefaces/issue-12854
Browse files Browse the repository at this point in the history
Fixed #12854 - Multiselect | Multiselect with string array search not working
  • Loading branch information
cetincakiroglu authored Feb 13, 2024
2 parents 23a80a2 + ed2c867 commit 160bfc2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/app/components/multiselect/multiselect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1038,11 +1038,20 @@ export class MultiSelect implements OnInit, AfterViewInit, AfterContentInit, Aft
return this.config.translation.aria ? this.config.translation.aria.close : undefined;
}


visibleOptions = computed(() => {
const options = this.group ? this.flatOptions(this.options) : this.options || [];

const isArrayOfObjects = ObjectUtils.isArray(options) && ObjectUtils.isObject(options[0])

if (this._filterValue()) {
const filteredOptions = this.filterService.filter(options, this.searchFields(), this._filterValue(), this.filterMatchMode, this.filterLocale);
let filteredOptions;

if (isArrayOfObjects) {
filteredOptions = this.filterService.filter(options, this.searchFields(), this._filterValue(), this.filterMatchMode, this.filterLocale);
} else {
filteredOptions = options.filter((option) => option.toLocaleLowerCase().includes(this._filterValue().toLocaleLowerCase()));
}

if (this.group) {
const optionGroups = this.options || [];
const filtered = [];
Expand Down
8 changes: 8 additions & 0 deletions src/app/components/utils/objectutils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
export class ObjectUtils {
public static isArray(value, empty = true) {
return Array.isArray(value) && (empty || value.length !== 0);
}

public static isObject(value, empty = true) {
return value instanceof Object && value.constructor === Object && (empty || Object.keys(value).length !== 0);
}

public static equals(obj1: any, obj2: any, field?: string): boolean {
if (field) return this.resolveFieldData(obj1, field) === this.resolveFieldData(obj2, field);
else return this.equalsByValue(obj1, obj2);
Expand Down

0 comments on commit 160bfc2

Please sign in to comment.