【问题标题】:Select2 3.4.5 force optgroup to be readonlySelect2 3.4.5 强制 optgroup 为只读
【发布时间】:2018-08-07 06:17:30
【问题描述】:

正如您在此处看到的,我可以将鼠标悬停在 optgroup 上,也可以单击它 有什么办法让它只读吗?

我的加载方式是:

formSelectElement.select2({
    placeholder: 'Type to search for a user...',
    minimumInputLength: 3,
    query: getCompanyUsers,
    multiple: true,
    maximumSelectionSize: formSelectElement.data('primary'),
    initSelection: setAssigneeInitSelection
});

【问题讨论】:

    标签: jquery drop-down-menu jquery-select2


    【解决方案1】:

    我已添加:

    .on("select2-selecting", function(e) {
        if (e.val == 0) {
            e.preventDefault()
            return;
        }
    });
    

    我不知道这是否是最好的选择(因为这应该是默认行为 - 用户不应该能够点击组)但它可以完成这项工作

    【讨论】:

    • 这不是必需的,因为optGroup 默认情况下是不可选的。
    • 就我而言,正如您在图像上看到的那样。我可以点击它并被选中
    猜你喜欢
    • 2019-12-18
    • 1970-01-01
    • 2015-08-29
    • 2018-08-18
    • 1970-01-01
    • 1970-01-01
    • 2015-01-13
    • 1970-01-01
    • 2018-08-07
    相关资源
    最近更新 更多