Level 3
if you have logic when click outside your dropdown menu, add this :
if ( your logic click outside menu ) {
$("[name='country']").select2('close');
}
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am using Select2 for my Select-Option. But I am facing a strange problem!!
Please see this gif.
While I clicking outside without selecting an option then the select2 search bar and results are remaining!!!
What is the problem?
My Code:
<div class="form-group">
<label for="country" class="countrySelectLabel">Country</label>
<select name="country" style="width: 100%!important;">
<option value="US" selected>USA</option>
</select>
</div>
Initialisation Code:
$("[name='country']").select2({
placeholder: "Select a country",
templateResult: formatCountry,
data: isoCountries,
templateSelection: selectedCountry,
});
if you have logic when click outside your dropdown menu, add this :
if ( your logic click outside menu ) {
$("[name='country']").select2('close');
}
Please or to participate in this conversation.