2014-08-28 69 views
0

我正在使用selectize0.11.0。我有一个多个<select>如何禁用选择输入和选项的顺序

我需要这样做。

  1. 禁止选择输入的顺序。
  2. 禁用选项的订单。

首先我选择了多个选项,然后我输入表单。 假设:我选择third,然后我选择first

选择的<input>应该是[third first]

当我重新提交表单而不更改任何内容时,刷新后的页面不会更改<select>中的选项顺序和<input>中的文本顺序。

的选择代码:

<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> 

我试了一下:

$('#{{ 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); 

我失去了价值,因为setValue只设置一个值来进行选择。

我把它放在jsfiddle jsfiddle,但它不能simulate提交。怎么做? 谢谢。

回答

0

那么,我将setValue()更改为addItems()来解决该问题,因为setValue()先清除所有项目,然后通过调用addItems()添加项目一次。