-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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: selectedOptions within selectedItemsTemplate not cleared #15277
Comments
+1 |
Facing the same issue. Any update? |
As a workaround you can patch the multiselect constructor locally https://github.com/primefaces/primeng/blob/master/src/app/components/multiselect/multiselect.ts#L1182 from: effect(() => {
const modelValue = this.modelValue();
const visibleOptions = this.visibleOptions();
if (visibleOptions && ObjectUtils.isNotEmpty(visibleOptions)) {
if (this.optionValue && this.optionLabel && modelValue) {
this.selectedOptions = visibleOptions.filter((option) => modelValue.includes(option[this.optionLabel]) || modelValue.includes(option[this.optionValue]));
} else {
this.selectedOptions = modelValue;
}
this.cd.markForCheck();
}
}); to: effect(() => {
const modelValue = this.modelValue();
const visibleOptions = this.visibleOptions();
if (visibleOptions && ObjectUtils.isNotEmpty(visibleOptions)) {
if (this.optionValue && this.optionLabel && modelValue) {
this.selectedOptions = visibleOptions.filter((option) => modelValue.includes(option[this.optionLabel]) || modelValue.includes(option[this.optionValue]));
} else {
this.selectedOptions = modelValue;
}
this.cd.markForCheck();
}
else if (this.selectedOptions?.length > 0) {
this.selectedOptions = [];
this.cd.markForCheck();
}
}); |
In this approach we clear values shown here |
As far as I understand the code here, the effect runs whenever |
Any updates on this? |
Describe the bug
When using a multiselect with
selectedItemsTemplate
template, the internalselectedOptions
variable is not always cleared correctly. Therefore a previous value is still rendered within the multiselect.Unfortunatly I am currently not able to reproduce this within a stackblitz issue template, but the problem is that the internal
selectedOptions
variable is not cleared when themodelValue
andvisibleOptions
is set to an empty array[]
.Because
visibleOptions
is empty here https://github.com/primefaces/primeng/blob/master/src/app/components/multiselect/multiselect.ts#L1122, the variableselectedOptions
is not updated and still has dirty state.As a workaround the following can be added:
I believe the bug was introduced with issue #14187
Environment
Latest
Reproducer
https://stackblitz.com/edit/github-8p6qdv?file=src%2Fapp%2Fapp.component.html
Angular version
17
PrimeNG version
17.13.0
Build / Runtime
Angular CLI App
Language
TypeScript
Node version (for AoT issues node --version)
20
Browser(s)
No response
Steps to reproduce the behavior
No response
Expected behavior
No response
The text was updated successfully, but these errors were encountered: