admin管理员组文章数量:1415664
I'm using select2 and I'm using it more or less like this:
<select id="e1">
<option value="AL">Alabama</option>
<option value="WY">Wyoming</option>
....
</select>
and the code
$('#e1').select2({ minimumResultsForSearch: -1 }) ;
With that option set to -1 it doesn't show the search box, but on the iPad/iPhone it does show the keyboard. Is there any way I can prevent the keyboard from showing ?
I'm using select2 and I'm using it more or less like this:
<select id="e1">
<option value="AL">Alabama</option>
<option value="WY">Wyoming</option>
....
</select>
and the code
$('#e1').select2({ minimumResultsForSearch: -1 }) ;
With that option set to -1 it doesn't show the search box, but on the iPad/iPhone it does show the keyboard. Is there any way I can prevent the keyboard from showing ?
Share Improve this question asked Sep 27, 2013 at 20:26 JohnnyJohnny 411 silver badge3 bronze badges3 Answers
Reset to default 3Using jQuery, add this to a container of your select2
$(".someSelect2Container input").prop("readonly",true);
I solved this problem for iOS:
$(document).ready(function() { $("select").select2(
.on("select2-selecting", function(e) {
setTimeout(function() {
document.activeElement.blur();
}, 500);
});
});
For people searching in the future if you're looking to keep the search functionality but STOP the keyboard from automatically popping up and taking up the screen space on mobile... the following worked for me (may be a faster/easier way to do it but I did it quickly to test and it worked and I was so excited I had to post it here):
window.select2typing = false;
$(document).on("focus",".select2-search__field",function(){
if(window.select2typing == false){
$(this).blur();
}
});
$(document).on("click",".select2-search__field",function(){
window.select2typing = true;
$(this).focus();
});
$("select").on("select2:close",function(){
window.select2typing = false;
});
This will stop the keyboard from popping up, stop it from auto-focusing the select2 search field and once they tap/click on the search field it'll give them the option to start typing.
本文标签: iosjavascriptselect2 keyboard shows when select is clickedStack Overflow
版权声明:本文标题:ios - javascriptselect2: keyboard shows when select is clicked - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745166005a2645682.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论