Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiselect: selectionLimit not working if the value 0 is provided #15810

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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