douju2599 2015-12-21 14:48
浏览 77
已采纳

允许用户单击select2并保留自由文本

I currently have a select2 dropdown, version 4.0, that allows the selection of items as well as free text to be typed.

    $("#dropdown").select2({
        placeholder: "Select or enter a new item",
        allowClear: true,
        tags: true
    });

I understand that typing free text creates a new option that can be clicked or will appear as an entry if the return key is pressed.

However clicking the newly entered option or hitting return are the ONLY ways for it to be accepted. This seems a little unintuitive as I know users will want to click onto other form elements or tab through the form.

Is there a way to allow a tag to be created just from de-focusing the form element?

I'm thinking something along the lines of having a .blur() event fire a selection or have select2:close cause a selection but I can't quite put it together.

  • 写回答

1条回答 默认 最新

  • douhan8581 2015-12-22 12:54
    关注

    It sounds like you are looking for the selectOnClose option. This will select the highlighted option when the drop down is closed.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作