Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

removeOnly or readOnly on change results in duplicated enty #217

Open
delkano opened this issue Jan 3, 2018 · 3 comments
Open

removeOnly or readOnly on change results in duplicated enty #217

delkano opened this issue Jan 3, 2018 · 3 comments
Labels

Comments

@delkano
Copy link

delkano commented Jan 3, 2018

I have a situation where I need to block a multiple select depending on the selections.
I've hooked a callback to the 'change' event of the select - or the selectivity div, it seems to make no difference - which checks the case and switches "removeOnly" to true if needed.
This is working wonderfully but for one thing: on the "selected" list, the last added item is duplicated. The underlying data is good, it's only a visual bug.

Since I know I am very bad at explaining, I've prepared a minimalistic jsfiddle which reproduces the error: https://jsfiddle.net/ta0v7uz9/

PS: it only happens when the Selectivity is created from a <select>.

@delkano
Copy link
Author

delkano commented Feb 21, 2018

I've looked a bit into the code and it seems to happen because, when the options are changed, there is a "change" event fired, which is handled by rerenderSelection.
Adding the item also fires a "change" event, but with an "added" object as argument.

The first event resolution renders all the current items (including the just added one); the second event resolution only renders a new item, the last one added.

I am not sure how to solve this. Commenting out the line 1831 (which associates rerenderSelection to the change event) seems to work out for me, but it may have unforeseen consequences.

@arendjr arendjr added the bug label Mar 9, 2018
@arendjr
Copy link
Owner

arendjr commented Mar 9, 2018

Thanks for the report! Unfortunately I don't have time to look into this deeply right now (I did do a quick check, but didn't see what triggers the "change" event when you call setOptions(), that shouldn't happen, I think...), but it sounds like you can work around it by calling setOptions inside a timeout.

@delkano
Copy link
Author

delkano commented Mar 9, 2018

How could I not think of a timeout? I updated the jsfiddle with one, and even with a 0ms delay it solves the issue. It's not ideal but as a workaround, at least, it works.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants