Skip to content

Commit

Permalink
Multiselect: selectionLimit not working if the value 0 is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
trigiacbmt committed Jun 7, 2024
1 parent e5f593e commit f023074
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/app/components/multiselect/multiselect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export class MultiSelectItem {
<ng-template #builtInFilterElement>
<div
class="p-checkbox p-component"
*ngIf="showToggleAll && !selectionLimit"
*ngIf="isSelectionAllDisabled()"
[ngClass]="{ 'p-variant-filled': variant === 'filled' || config.inputStyle() === 'filled', 'p-checkbox-disabled': disabled || toggleAllDisabled }"
(click)="onToggleAll($event)"
(keydown)="onHeaderCheckboxKeyDown($event)"
Expand Down Expand Up @@ -1216,7 +1216,7 @@ export class MultiSelect implements OnInit, AfterViewInit, AfterContentInit, Aft
}

maxSelectionLimitReached() {
return this.selectionLimit && this.modelValue() && this.modelValue().length === this.selectionLimit;
return ObjectUtils.isNotEmpty(this.selectionLimit) && this.modelValue() && this.modelValue().length === this.selectionLimit;
}

ngAfterContentInit() {
Expand Down Expand Up @@ -1461,6 +1461,10 @@ export class MultiSelect implements OnInit, AfterViewInit, AfterContentInit, Aft
return ObjectUtils.isNotEmpty(this.modelValue());
}

isSelectionAllDisabled() {
return this.showToggleAll && ObjectUtils.isEmpty(this.selectionLimit)
}

isValidSelectedOption(option) {
return this.isValidOption(option) && this.isSelected(option);
}
Expand Down Expand Up @@ -1993,7 +1997,12 @@ export class MultiSelect implements OnInit, AfterViewInit, AfterContentInit, Aft

writeValue(value: any): void {
this.value = value;
this.modelValue.set(this.value);
if (!ObjectUtils.isEmpty(this.selectionLimit)) {
this.modelValue.set([]);
} else {
this.modelValue.set(this.value);
}

this.cd.markForCheck();
}

Expand Down

0 comments on commit f023074

Please sign in to comment.