Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to select blank option with selectOnClose=true & allowClear=true #5646

Open
jmalatia opened this issue Sep 20, 2019 · 7 comments
Open

Comments

@jmalatia
Copy link

Unable 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:

  1. Select an option in select2
  2. Click the X to clear the option
  3. 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.

@kevin-brown
Copy link
Member

Contrary to everything I've said in the past about it, I believe this is one of the cases where we need to enable #3320 as a default behaviour.

As far as I can tell, this issue exists for all versions going back to 4.0.1. I can't reproduce it on 4.0.0 because this combinations of options caused a stack overflow (fixed in 393ca4c).

@stale
Copy link

stale bot commented Nov 22, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the status: stale label Nov 22, 2019
@jmalatia
Copy link
Author

Bump

@stale stale bot removed the status: stale label Nov 22, 2019
@stale
Copy link

stale bot commented Jan 21, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the status: stale label Jan 21, 2020
@stale stale bot closed this as completed Jan 28, 2020
@kevin-brown kevin-brown reopened this Jan 28, 2020
@stale stale bot removed the status: stale label Jan 28, 2020
@tobiasnitsche
Copy link

Bump

@itsnunolemos
Copy link

itsnunolemos commented Jan 31, 2021

+1, this bug is reported in 2016 #4579

@vetezeTE
Copy link

vetezeTE commented Feb 26, 2021

I added an additional check at the top of _handleSelectOnClose and that seems to have given me the result I'm expecting... for now.

SelectOnClose.prototype._handleSelectOnClose = function (_, params) {

    if (params && params.originalEvent == null) {
        return;
    }
    // etc...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants