Can't type in Select2 dropdown input search field (http://kevin-brown.com/select2/)
I have found many issues listed which mentions the same problem but nothing worked for me (https://www.google.com/search?q=can%27t+type+in+select2&ie=utf-8&oe=utf-8&client=firefox-b-ab). I can't type in Select2 dropdown input search field in model dialog using jQuery. By the way i can select value fine from dropdown. Tried inserting tabindex: 0 but no luck.
$.ajax({
type: "POST",
url: "<?php echo $myScripts; ?>",
data: { id1: "get-release-dropdown-html", id100: "<?php echo $dbTable; ?>" },
success:function(releaseDropdown){
$('#progress').hide();
$( "#modelDialog1" ).dialog({
modal: true,
width: '570',
height: '600',
resizable: true,
position:
{
my: "center",
at: "center",
of: window,
},
title: "Trigger Build",
open: function() {
$(this).html("<br/>Please select job options.<br/><br/><br/><b>Release:</b>" + releaseDropdown + "<div style='margin-top:30px;'/><b>Build Release Candidate:</b><select id='sReleaseCandidate'><option value='ga' selected>GA</option><option value='beta1'>BETAX</option>'></br>");
$("#sDescription").focus();
$("#sRelease, #sReleaseCandidate").select2({
tags: true
});
},
close: function() {
$( this ).dialog( "close" );
},
});
}
});
select2 is not a function" jQuery error occurs for multiple reasons: Forgetting to include the select2 library. Loading the select2 library before the jQuery library. Loading the jQuery library twice.
Select2 does not function properly when I use it inside a Bootstrap modal. This issue occurs because Bootstrap modals tend to steal focus from other elements outside of the modal. Since by default, Select2 attaches the dropdown menu to the <body> element, it is considered "outside of the modal".
By default, Select2 will attach the dropdown to the end of the body and will absolutely position it to appear above or below the selection container. Select2 will display the dropdown above the container if there is not enough space below the container, but there is enough space above it.
Select2 gives you a customizable select box with support for searching, tagging, remote data sets, infinite scrolling, and many other highly used options.
As indicated in https://github.com/select2/select2/issues/600#issuecomment-102857595
You need to specify modal dialog element as parent for select2, that will make sure focus remains with the modal even though you have clicked on select element
$("#sRelease, #sReleaseCandidate").select2({ tags: true, dropdownParent: $("#modelDialog1") });
If you're using Bootstrap Modal then just remove tabindex="-1" from the bootstrap modal attribute. In my case it worked very nicely.
I've been fighting with this the whole week after an update. What works in one case, it doesn't in other, either is it not properly placed, or cannot be controlled. And testing is not easy either...
At this time, what seems to work best is just to select the real parent of the dropdown... something select2
could very easily do.
$(".select2").each((_i, e) => {
var $e = $(e);
$e.select2({
tags: true,
dropdownParent: $e.parent()
});
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With