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 Not Displaying Pre-Selected Items Upon Load #9673

Closed
lazyeye73 opened this issue Dec 17, 2020 · 7 comments
Closed

MultiSelect Not Displaying Pre-Selected Items Upon Load #9673

lazyeye73 opened this issue Dec 17, 2020 · 7 comments
Assignees
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@lazyeye73
Copy link

I'm submitting a ...

[x] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35

Current behavior
When a MultiSelect is used in a reactive or template-driven form and the options are populated in an delayed manner (whether asynchronously via an API call or through the use of setTimeout), the initially-selected items are not displayed in the MultiSelect placeholder.

Expected behavior
As in previous versions of PrimeNG, the pre-selected items in the MultiSelect appear comma-separated in the MultiSelect placeholder.

Minimal reproduction of the problem with instructions
https://stackblitz.com/edit/github-tidqpm

  • Angular version: 11.0.5

  • PrimeNG version: 11.0.0

  • Browser: [all]

  • Language: [TypeScript 3.8.3+]

Code Fix
This issue can be addressed by changing the "options" setter to update the label and check the filled state, similar to the following:

    set options(val) {
        this._options = val;
        this.updateLabel();
        this.updateFilledState();
        this.checkSelectionLimit();
        this.cd.markForCheck();
    }
@yigitfindikli yigitfindikli added the Status: Pending Review Issue or pull request is being reviewed by Core Team label Dec 25, 2020
@yigitfindikli yigitfindikli self-assigned this Dec 25, 2020
@jacqueslareau
Copy link

I'm having the same issue with PrimeNG 11.0.0 and Angular 11.0.4

@markusvorraber
Copy link

Also same problem here, PrimeNg 11.1.0 and Angular 11.0.7.

@thekip
Copy link

thekip commented Jan 25, 2021

Confirm, just add this.updateLabel(); in options setter is enough to re-render label when options loaded.

@zbogdanov
Copy link

Hi. It has been over a month now and this bug hasn't been even reviewed. Do we know any ETA on at least starting to fix it? We have numerous hacks through out our codebase to circumvent this issue that worked fine in previous versions...

Thanks!

@scurk1415
Copy link

Yeah i also have the same problem. Had to revert back to v10

@chad-smith
Copy link

I'm also seeing this issue. Is there a workaround?

@Dador
Copy link
Contributor

Dador commented Mar 18, 2021

Issue still occurs in latest version (11.3.1).

Workaround:

  1. Add placeholder (using property):
    <p-multiSelect ... [placeholder]="citiesPlaceholder"></p-multiSelect>
export class ExampleComponent {
    ...
    citiesPlaceholder = '';
    ...
}
  1. Set placeholder property after loading options:
this.settingsForm.patchValue({
...
};
this.citiesPlaceholder = 'Select';

P.S. Setting/updating placeholder calls updateLabel(), so fix suggested by @thekip should help.

@yigitfindikli yigitfindikli added Type: Bug Issue contains a bug related to a specific component. Something about the component is not working and removed Status: Pending Review Issue or pull request is being reviewed by Core Team labels Apr 6, 2021
@yigitfindikli yigitfindikli added this to the 11.3.2 milestone Apr 6, 2021
yigitfindikli added a commit that referenced this issue Apr 6, 2021
Fixed #9673 - MultiSelect Not Displaying Pre-Selected Items Upon Load
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

No branches or pull requests

9 participants