groenroos / minimalect

Minimal select replacement for jQuery
350 stars 52 forks source link

Removing traces of Minimalect instance, then re-applying results in nothing #33

Closed flovan closed 11 years ago

flovan commented 11 years ago

I have a subcategory select which is populated with new options each time the category select changes its value. On each change, I:

But then nothing happens.. I would expect at least an error or something, but I'm left in the dark. Any idea on how to handle this properly?

groenroos commented 11 years ago

You likely don't need to nuke Minimalect just to update the selections. Did you try .trigger("change") on the original subcategory select? That should wake up Minimalect to update the choices.

flovan commented 11 years ago

No success with that.. I see the original select options updating, after which I call change() or trigger('change'), but the plugin generated drop-down remains the same. I know destructing it probably isn't the way to go, but I am still wondering why it isn't working. If no other options remain, I will have to re-add the entire select into the DOM and hope for that to succeed, but I'd prefer to avoid that.

flovan commented 11 years ago

I found the issue!

In the change handler on the original element, the layout update was only done when the select had a value selected. I added following code below line 106 (where the if ends):

else m.ul.html(markup+'<li class="'+m.options.class_empty+'">'+m.options.empty+'</li>');

This actually puts the updated <ul>into the DOM, even when the select value was empty.

groenroos commented 11 years ago

Glad you found a solution! I'll keep that in mind for the next version!