简体   繁体   English

文本输入上的 Select2 4.0.5 触发事件

[英]Select2 4.0.5 trigger event on Text input

in an earlier version of select2 I was able to fire an event with select2-selecting when typing into the search box.在 select2 的早期版本中,我可以在输入搜索框时使用 select2-selecting 触发一个事件。 In 4.0.5, with select2:selecting, it seems to not work anymore.在 4.0.5 中,使用 select2:selecting,它似乎不再起作用了。 Anyone knowing a working solution?有人知道可行的解决方案吗? I want to send an ajax request to my sever everytime I type into the searchbar of the select2.每次我在 select2 的搜索栏中键入内容时,我都想向我的服务器发送一个 ajax 请求。 Like I said in an earlier version that was possible!就像我在早期版本中所说的那样,这是可能的! Thanks for any advice.感谢您的任何建议。

You have to put select2 on a select item in 4.x您必须将 select2 放在 4.x 中的选择项上

https://select2.org/data-sources/ajax https://select2.org/data-sources/ajax

Did it acording to that example and it worked.按照那个例子做了,它奏效了。

I had to change the html element from input to select.我不得不将 html 元素从输入更改为选择。 Input worked with older versions of select2 but not with 4.x输入适用于旧版本的 select2,但不适用于 4.x

old html旧的html

<input id="groupSelect" name="group_id" type="text" style="max-width: 100%; width: 100%;" required>

new html新的 html

<select id="groupSelect" name="group_id" type="text" style="max-width: 100%; width: 100%;" required></select>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM