[英]Select2 4.0 - Keypress does not trigger selection
I've upgraded Select2
from version 3.5.2
to version 4.0.
我已将
Select2
从版本3.5.2
升级到版本4.0.
We have plenty of forms with many fields filled in by typists. 我们有很多形式,打字员填写了很多字段。
In the old version ( 3.5.2
) the typists would use the following sequence: 在旧版本(
3.5.2
)中,打字员将使用以下顺序:
Tab
to both select the result and move on to the next field Tab
选择结果并转到下一个字段 $("select").select2();
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/3.5.2/select2.min.css" rel="stylesheet" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/3.5.2/select2.min.js"></script> <style> input { display:block; margin:10px 0; } </style> <input type=text/> <select> <option value="1">1. Option A</option> <option value="2">2. Option B</option> <option value="3">3. Option C</option> <option value="4">4. Option D</option> <option value="5">5. Option E</option> </select> <input type=text/>
On version 4.0
the typists must: 在
4.0
版本打字员必须:
Enter
Enter
Enter
again Enter
$("select").select2();
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.min.css" rel="stylesheet"/> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.min.js"></script> <style> input { display:block; margin:10px 0; } </style> <input type=text/> <select> <option value="1">1. Option A</option> <option value="2">2. Option B</option> <option value="3">3. Option C</option> <option value="4">4. Option D</option> <option value="5">5. Option E</option> </select> <input type=text/>
Is there a way around this apparent downgrade in functionality? 有没有办法绕过这种明显的功能降级? I don't want to resort to
v3.5.2
because I'm using AJAX on <select>
elements which is not supported in this version (one must use hidden <input>
tag instead) 我不想诉诸
v3.5.2
因为我在<select>
元素上使用AJAX,这个版本不支持(必须使用隐藏的<input>
标签)
To trigger the opening of select2 on focus use jQuery's native "focus" event & select2 "open" event. 要在焦点上触发select2的打开,请使用jQuery的原生“焦点”事件和select2“open”事件。 Important: Make it on DOM is ready.
重要提示:在DOM上做好准备就绪。
$( document ).ready(function() { $(".select2-selection").on("focus", function () { $(this).parent().parent().prev().select2("open"); }); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.