Closed authyrtyr closed 8 years ago
Has anyone found the solution to this? I'm having the same problem sort of. The difference is that I don't have anything behind a hidden element. The multiselects load on the page and then the plugin does it's thing but if you inspect the checkbox element the "value" attribute is blank. If I console log the checkbox during the creation stage it says that the value is correct based on the select list but if I console log the "change" function value it's an empty string. I'm going nuts. Spent hours trying to fix this.
I've been able to sort of solve it by running $("select").multiselect('rebuild');
every time I show()
the surruondings. Certainly not perfect and it needs a bug fix but if you need your project to work I recommend trying this.
@authyrtyr Thanks for the tip! I do have other non-multiple selects on the page so I had to do it by class or id, but that worked for all but the last one. The last one actually gets duplicated, the new one doesn't have the template applied but it is at least functional. I tried adding a delay on the rebuild. I tried renaming and everything else I could think of. Not sure why that one is having this problem. Thanks for the help though. The rebuild did the trick on the rest though.
I have not checked this yet, but as you were able to trace the problem to coming form the checkbox value being empty, this may be a result of the following line in your code:
$("#toggleAddUserForm").click(function(){
// The following line resets all values, including checkboxes!
// You intend to reset all selections and user input, but you would have to do this for
// text inputs and checkboxes separately, because setting the value to "" for a
// checkbox does not reset the selection!
$("#addUserPanel select,input").val("");
$("#addUserPanel").slideToggle();
});
I may add a similar example to the documentation, anyway just in case I am missing something.
I had a similar error and it was because I was changing the value of a checkbox used internally by the multiselect. It looks like you are doing the same:
$("#addUserPanel select,input").val("");
This probably selects more than what you think it does. Try to increase the specificity.
If you have a div that's hidden and then shown that's containing a multiple select then you get an error when any of the options is clicked on. The exact error message
TypeError: $option is undefined
on line 477. After putting in some simple prints into the multiselect JS file I found that the source as far as I could follow was that $target.val() was an empty string. I was able to somewhat fix the problem in my site by creating the HTML for my select in the page after my show completed and then running multiselect then but it causes a jumpy effect during the show that isn't ideal. Here's my code that's generating the error. I'm using jQuery version 2.1.3 (but I also got the error with 1.10.1 which I was using before). I'm using bootstrap 3.x.