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

Cannot read property 'listElement' of undefined #103

Open
smparsons opened this issue Feb 4, 2016 · 2 comments
Open

Cannot read property 'listElement' of undefined #103

smparsons opened this issue Feb 4, 2016 · 2 comments
Labels

Comments

@smparsons
Copy link

I ran into this error when trying to programmatically deselect elements from my multiselect. I was following the documentation, and used this code:

var selected = $('.sponsor-multiselect').find('option:selected');
selected.remove();
$('.sponsor-multiselect').multiselect('refresh');

I figured this might be an issue with my code, so I went to the demo page and tried executing this same code against one of the multiselects on the page, and it still threw the same error. Thanks for the help.

@yanickrochon
Copy link
Owner

I see the problem; the refresh method does not clear the cache from removed options. I'll try to resolve this as soon as I can.

@smparsons
Copy link
Author

So I was sort of pressed for time on my project, so I attempted to make a fix for this. I don't know if this helps, but I was able to make a workaround. I created a 'select' public function that looks like this:

select: function(elements) {
  for (var i = 0; i < elements.length; i++)
  {
    var eData.this.optionCache._elements[$(elements[i]).data('element-index')];
    if (eData != undefined)
    {
      this.optionCache.setSelectedSorted(eData, !eData.selected);
    }
  }
}

And then all I have to do is get the elements I want to select or deselect, and then just call $(multiselect).multiselect('select', elements); But I can't tell exactly how hacky this is (not too familiar with the code for this plugin). It appears to work, and this removes the need to call the refresh function. This code makes use of the "setSelected" functionality that the event that listens to element clicks uses.

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

No branches or pull requests

2 participants