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

option ignored if both option and optgroup are direct children of select #5

Open
savvan0h opened this issue Nov 12, 2019 · 0 comments

Comments

@savvan0h
Copy link

If both option and optgroup are direct children of select (as shown in the example below), option is ignored when appending anchor .
As a result, direct options don't show up and clicking on a button makes a wrong choice because data-select-index has a wrong index .

<select>
  <option value="" selected>...</option>
  <optgroup label="foo">
    <option value="1">...</option>
    <option value="2">...</option>
    <option value="3">...</option>
  </optgroup>
</select>

The cause of the problem is that the following code ignores direct options if select has optgroup:

jQuery.select2Buttons.js

    var optGroups = select.children('optgroup');
    if (optGroups.length == 0) {
      addOptGroup(select);
    }else{
      optGroups.each(function(){
        addOptGroup($(this));
      });
    }

As for the above example, adding addOptGroup(select); right above optGroups.each solves the problem, but it doesn't work in the case option is not always defined above optgroup .

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

No branches or pull requests

1 participant