Reputation: 3736
I am using selectize0.11.0. I have a multiple <select>
.
I need to do this.
First I select multiple option, and then I sumbmit the form.
Suppose: I select third
and then I select first
.
The <input>
of selectize should be [third first]
.
When I resubmit the form without changing anything, the page after refresh would not change the order of options in <select>
and texts in <input>
.
The select code:
<select id="id_sel" multiple='multiple'>
<option selected='selected' value='1'>first</option>
<option value='2'>second</option>
<option selected='selected' value='3'>third</option>
</select>
What I tried:
$('#{{ filterform.plf.auto_id }}').selectize({maxItem:2});
plf_sel = $('#{{ filterform.plf.auto_id }}')[0].selectize;
plf_sel.clear();
plf_sel.clearOptions();
plf_sel.renderCache['option'] = {};
plf_sel.renderCache['item'] = {};
plf_sel.addOption(plf_sel_option);
plf_sel.setValue(plf_sel_option[0].value);
//plf_sel.setValue(plf_sel_option[1].value);
I lost a value, since setValue
only set one value to be selected.
I put it on jsfiddlejsfiddle, but It can not simulate submit. how to do that? Thanks.
Upvotes: 1
Views: 1766
Reputation: 3736
Well, I change setValue()
to addItems()
to solve that problem, since setValue() clear all items first and then add item by calling addItems() once.
Upvotes: 1