This issue was posted by Pedro Monteiro by my request, so, maybe i can better explain it myself.
This issue reported was an example, i'll try to summarize the true problem.
Initially we had a select box with over 40k entries, which was making the website getting very slow. Due to that we've started using an external module called Selectize.
What selectize does is to hide the initial select box and removes all entries in there and then creates his own div with all the entries that should be in the initial select box.
In practical terms what happens is this:
BEFORE:
<select id='test'>
<option value=1>test1</option>
<option value=2 selected>test2</option>
<option value=3>test3</option>
</select>
AFTER CALLING SELECTIZE:
<select id='test>
<option value='2' selected>test2</option>
</select>
<div id='test-selectize'>
<div data-value=1>test1</div>
<div data-value=2>test2</div>
<div data-value=3>test3</div>
</div>
What happens is that each time i select an option in the selectize generated combobox he creates that selected item in the initial select box and puts it selected.
So in the initial select box i'll only have the 'real, selected value'.
Until here everything's perfect. The problem that we're now facing is that this is a project with over 4 years of development with thousands of code lines.
And there are many code lines that will force the selection of value via jquery to a select box. Something like this $('#test').val(3);
But now since we're using the Selectize module, the initial select box does not have that option on it.
So what we wanted to do is almost a try/catch, so when i try to change the value of my initial select box via code i grab that event and instead of 'changing' the value of the select box i'll call my own function which will select the value on the Selectize module instead.
The easy solution would be to grab all code done during the past 4 years and in each place where i'm forcing the .val on a select box i'll re-write it to use the new module, but, this is very time consuming and of course bugs will appear for sure.
Hope this has explained better the problem.