Reputation: 21
I have a select
element with a few option
elements, but the dropdown menu will not close after I open it.
I don't know why it doesn't work on my project but it works perfectly fine on a new project.
$(document).ready(function() {
$('#user-selection').select2();
});
<select id="user-selection" name="userId" style="width: 100%" required>
<option>1</option>
<option>2</option>
<option>3</option>
</select>
Am I missing something out?
Update: Changed to correct version of Select2 which made the problem go away
Upvotes: 2
Views: 2015
Reputation: 56
This error at last version of select2, you can use the file I attached I edit focus event at select2.js
this.on("focus", function () {
a.$container.addClass("select2-container--focus"),
a.$container.hasClass("select2-container--disabled") || a.isOpen() && (a.options.get("multiple") ? window.setTimeout(function () {
a.open()
}, a.options.get("ajax") ? 300 : 100) : a.open())
}),
from a.isOpen() ||
to a.isOpen() &&
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6/css/select2.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://dits.cloud/js/select2.js"></script>
<select id="user-selection" name="user" style="width: 100%" required>
<option>1</option>
<option>2</option>
<option>3</option>
</select>
<script>
$(document).ready(function () {
$('#user-selection').select2();
});
</script>
Upvotes: 3