Skip to content

Commit

Permalink
Fixed primefaces#15229: keep pre-selected disabled options selected w…
Browse files Browse the repository at this point in the history
…hen filtering and checking toggleAll

primefaces#15229
  • Loading branch information
Thai Ha committed Apr 8, 2024
1 parent ede7876 commit 856f366
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/app/components/multiselect/multiselect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1840,17 +1840,23 @@ export class MultiSelect implements OnInit, AfterViewInit, AfterContentInit, Aft
checked: !this.allSelected()
});
} else {
const value = this.allSelected()
// pre-selected disabled options should always be selected.
const selectedDisabledOptions = this.getAllVisibleAndNonVisibleOptions()
.filter((option) => this.isSelected(option) && (this.optionDisabled ? ObjectUtils.resolveFieldData(option, this.optionDisabled) : option && option.disabled !== undefined ? option.disabled : false))

const visibleOptions = this.allSelected()
? this.visibleOptions()
.filter((option) => !this.isValidOption(option) && this.isSelected(option))
.map((option) => this.getOptionValue(option))
: this.visibleOptions()
.filter((option) => this.isSelected(option) || this.isValidOption(option))
.filter((option) => this.isSelected(option) || this.isValidOption(option));

const optionValues = [...selectedDisabledOptions, ...visibleOptions]
.map((option) => this.getOptionValue(option));
const value = [...new Set(optionValues)];

this.updateModel(value, event);

// because onToggleAll could have been called during filtering, this additional test needs to be performed before calling onSelectAllChange.emit
// because onToggleAll could have been called during filtering, this additional test needs to be performed before calling onSelectAllChange.emit
if (!value.length || value.length === this.getAllVisibleAndNonVisibleOptions().length) {
this.onSelectAllChange.emit({
originalEvent: event,
Expand Down

0 comments on commit 856f366

Please sign in to comment.