Unable to select blank option with selectOnClose=true & allowClear=true
See original GitHub issueUnable to select blank option with selectOnClose=true & allowClear=true
Sample pen: https://codepen.io/jmalatia/pen/wvwQqXw
Sample code
<form>
<div class="form-group>
<label for="Order_RecdViaId">RecdViaId</label>
<select class="form-control select2" autofocus="" id="Order_RecdViaId" name="Order.RecdViaId" >
<option></option>
<option value="4">Ground - UPS</option>
<option value="5">3-Day - UPS Orange</option>
<option value="6">2-Day - UPS Blue</option>
<option value="7">1-Day PM - UPS Red Saver ~4:30pm</option>
<option value="8">1-Day AM - UPS Red ~10:30am</option>
</select>
</div>
<br />
<div class="form-group">
<label for="ctl2">Control2</label>
<input type="text" id="ctl2" name="ctl2" class="form-control" />
</div>
</form>
<script>
$(document).ready(function () {
$("select.select2").select2({
placeholder: "Select an option...",
selectOnClose: true,
allowClear: true
});
});
</script>
select2 v4.0.10 tested on Windows 10 Chrome 77
Steps to reproduce in supplied pen:
- Select an option in select2
- Click the X to clear the option
- First option is selected instead of the first, blank option.
What is expected: The first blank option should be selected and/or the first blank option should be in the list so it can be selected manually.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:7 (1 by maintainers)
Top Results From Across the Web
default select option as blank - html - Stack Overflow
select an option -- Will be displayed by default. But if you choose an option, you will not be able to select it...
Read more >Should a blank option always be included in <select> inputs?
If this is a required field, then the "please select" option is never valid during an edit, and therefore should not be included...
Read more >Cannot get Custom Select List "On Change" event to work with ...
I have a custom select list that is populated by a data master, and the first record in the data master is a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
+1, this bug is reported in 2016 https://github.com/select2/select2/issues/4579
I added an additional check at the top of _handleSelectOnClose and that seems to have given me the result I’m expecting… for now.