ehynds / jquery-ui-multiselect-widget

jQuery UI MultiSelect widget

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Widget issues if included multiple times

Limos opened this issue · comments

I'd accidentally included a second <script> reference to include this multiselect widget, which caused some very strange bugs. (The second reference was located in a jQuery UI dialog who's content was being loaded from the server.)

After some investigation, I tracked it down to the use of 'var multiselectID = 0;' was causing the same ID values to be used for instances of the widget in both the parent form and the jQuery UI dialog content. This situation was causing changes in the dialog instance to trigger events in the parent form instance.

I need to load mutliselect from the jQuery-UI dialog because that widget and content is referenced from multiple pages on the site, only a few of which also use multiselect.

I was able to resolve my issue via the following change to the multiselect widget source:

-var multiselectID = 0;
+var multiselectID = jQuery.guid++;

Note that I am not sure if this is appropriate use of jQuery.guid, but it seems to be working well for me.

Looks like we should probably go with the jQuery uniqueId function described here. Although using that correctly will be more of a change.

jQuery.guid seems like it would be okay but people are recommending against it on stack overflow since jQuery is also using it internally for some event logic.

I don't think I'm going to fix this in the main repo, including the source code multiple times is a strange thing to do.