ng-multiselect-dropdown icon indicating copy to clipboard operation
ng-multiselect-dropdown copied to clipboard

single select with nothing selected yet does not work

Open tilda-zz opened this issue 1 year ago • 2 comments

Angular version: latest

ng-multiselect-dropdown version:

Description of issue: used the single select version. When add of a new record. So there is nothing selected yet in the dropdown. When I then select something I get the next error:

"core.mjs:6362 ERROR TypeError: Cannot read properties of undefined (reading 'id') at MultiSelectComponent.onItemClick (ng-multiselect-dropdown.mjs:169:51) at MultiSelectComponent_li_13_Template_li_click_0_listener (ng-multiselect-dropdown.mjs:392:4901) at executeListenerWithErrorHandling (core.mjs:14931:16) at wrapListenerIn_markDirtyAndPreventDefault (core.mjs:14966:22) at HTMLLIElement. (platform-browser.mjs:459:38) at _ZoneDelegate.invokeTask (zone.js:406:31) at Object.onInvokeTask (core.mjs:26299:33) at _ZoneDelegate.invokeTask (zone.js:405:60) at Zone.runTask (zone.js:178:47) at ZoneTask.invokeTask [as invoke] (zone.js:487:34)"

codeline in ng-multiselect-dropdown.mjs:

onItemClick($event, item) {
    if (this.disabled || item.isDisabled) {
        return false;
    }
    if (this._settings.singleSelection) {

        if (item.id !== this.selectedItems[0].id) {                   ////this is the problem line, there is nothing in this.selectedItems yet. So first time select is not working !!! 
            this.addSelected(item);
        }
    }
    else {
        const found = this.isSelected(item);
        console.log({ item, selectedItems: this.selectedItems });
        const allowAdd = this._settings.limitSelection ==

tilda-zz avatar Jul 20 '22 08:07 tilda-zz

Same issue here, seems like a bug with the latest version, to be fair it is labelled as beta, I downgraded it to [0.3.8] which solved the issue for me.

stevenrlp avatar Jul 20 '22 14:07 stevenrlp

Yes! I downgraded to 0.3.8 and now it works! Thx

tilda-zz avatar Aug 09 '22 10:08 tilda-zz