Skip to content

Commit

Permalink
Fix/primefaces#6216 MultiSelect - SelectionLimit issue (primefaces#6218)
Browse files Browse the repository at this point in the history
* fix: 6216  disabled option with selectionLimit

* fix: 6216 handle selectionLimit select all

* Update MultiSelect.js

* Update MultiSelect.js

* Update MultiSelect.js

---------

Co-authored-by: Melloware <[email protected]>
  • Loading branch information
charithAmila and melloware authored Apr 13, 2024
1 parent d8c7f7d commit 0a3d4e7
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions components/lib/multiselect/MultiSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,11 @@ export const MultiSelect = React.memo(
}
}

// make sure not to exceed the selection limit
if (props.selectionLimit && value && value.length) {
value = value.slice(0, props.selectionLimit);
}

updateModel(event.originalEvent, value, value);
}
};
Expand Down Expand Up @@ -681,11 +686,20 @@ export const MultiSelect = React.memo(
};

const isOptionDisabled = (option) => {
if (props.optionDisabled) {
return ObjectUtils.isFunction(props.optionDisabled) ? props.optionDisabled(option) : ObjectUtils.resolveFieldData(option, props.optionDisabled);
// disable if we have hit our selection limit
if (!allowOptionSelect() && !isSelected(option)) {
return true;
}

// check if custom optionDisabled function is being used
const { optionDisabled } = props;

if (optionDisabled) {
return ObjectUtils.isFunction(optionDisabled) ? optionDisabled(option) : ObjectUtils.resolveFieldData(option, optionDisabled);
}

return option && option.disabled !== undefined ? option.disabled : false;
// fallback to the option itself disabled value
return option && (option.disabled ?? false);
};

const isOptionValueUsed = (option) => {
Expand Down

0 comments on commit 0a3d4e7

Please sign in to comment.