primeng icon indicating copy to clipboard operation
primeng copied to clipboard

Select multiple items in listbox based on array with values

Open xv-k opened this issue 9 years ago • 3 comments

I'm submitting a ... (check one with "x")

[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 Loading selected items (with ngModel) into the listbox only works with primitives as value (string, integer, ...), but when the value is an object there is strange behavior (e.g. items are not selected, when selecting an item that is already in the list it adds the item as a duplicate to the list, to remove the item you have to deselect twice to get rid of it)

Expected behavior load selected list items from a list of objects

Minimal reproduction of the problem with instructions

HTML <p-listbox multiple="multiple" checkbox="checkbox" [options]="list" [(ngModel)]="selectedList" filter="true" appendTo="body"></p-listbox>

TS

public list= [
        { label: 'one', value:  { id: '111' } },
        { label: 'two', value:  { id: '222' } },
        { label: 'three', value:  { id: '333' } }
 ]

public selectedList: any = []

 ngOnInit() {
         this.selectedList = [{ id: '222' }];
}

xv-k avatar May 03 '17 14:05 xv-k

I have the same problem. Any solution?

mizdler avatar Jun 12 '17 21:06 mizdler

Not a real solution, but I use two arrays now (one with id's and one with the objects) and that works.

I found this here: https://github.com/primefaces/primeng/issues/1010

xv-k avatar Jun 13 '17 10:06 xv-k

Unable to replicate, please provide a test case based on plunkr below and we'll review again. I've checked the code and it should work as well.

http://plnkr.co/edit/Wj39h1?p=preview

cagataycivici avatar Jun 23 '17 07:06 cagataycivici