I am having similar problems with select2 plugin. I donโt know exactly what functions you use specially, but in my experience, when you set the element as select2 in the document.ready event, the plugin will change some of the elementโs attributes on the fly (check one of the elements after the page has finished loading - often you see that the id and class properties are different from what you see when viewing the source).
It's hard to offer more without seeing the code, but here are a few ideas to help you get started:
First of all, make sure you have a link to your select2.css stylesheet in the header.
Then, since you are talking about form submissions, I would advise you to check if you get a complete response or submit via AJAX (if you use jQueryMobile, you use AJAX if you do not override this in jquerymobile.js file or set data-ajax="false" in your form attributes). You can just look at the value returned by Request.IsAjaxRequest() for this. Obviously, if you send via ajax, you will not get into the document.ready event, and select2 will not initialize correctly, and you will need to figure out how to do this. Try refreshing the page after submitting and see if it displays the select2 component.
Then I suggest that you examine the elements and see if they behave as you expected, because you are actually trying to work with classes that the plugin has reassigned at runtime. You can either simply customize your logic, or you can delve into the select2 code itself and change the behavior - in fact, it is well documented what the code does, and if you jump in the Google group for select2, Igor is usually pretty quick to answer questions .
source share