如何禁用输入顺序和选择中的选项

how to disable order for input and options in selectize

本文关键字:选项 选择 何禁用 输入 顺序      更新时间:2023-09-26

我使用的是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只设置了一个要选择的值。

我把它放在jsfiddlejsddle上,但它不能模拟提交。怎么做?谢谢

好吧,我将setValue()更改为addItems()来解决这个问题,因为setValue()首先清除所有项,然后通过调用addItems()一次来添加项。