jquery.select2Buttons icon indicating copy to clipboard operation
jquery.select2Buttons copied to clipboard

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

Open savvan0h opened this issue 6 years ago • 0 comments

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 .

savvan0h avatar Nov 12 '19 08:11 savvan0h