Skip to content

Commit

Permalink
Merge pull request #15810 from trigiacbmt/issue-15400-v2
Browse files Browse the repository at this point in the history
Multiselect: selectionLimit not working if the value 0 is provided
  • Loading branch information
cetincakiroglu authored Jun 13, 2024
2 parents 47fa80b + 114e4c1 commit 551eb40
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) && ObjectUtils.isEmpty(this.value)) {
this.modelValue.set([]);
} else {
this.modelValue.set(this.value);
}

this.cd.markForCheck();
}

Expand Down

0 comments on commit 551eb40

Please sign in to comment.