Select2 will correctly handle disabled options, both with data coming from a standard select (when the `disabled` attribute is set) and from remote sources, where the object has <code>disabled: true</code> set.
var $disabledResults = $(".js-example-disabled-results");
$disabledResults.select2();
</script>
## Automatic selection
Select2 can be configured to automatically select the currently highlighted result when the dropdown is closed by using the `selectOnClose` option:
```
$('select').select2({
selectOnClose: true
});
```
## Forcing the dropdown to remain open after selection
You may use the `closeOnSelect` option to prevent the dropdown from closing when a result is selected:
```
$('select').select2({
closeOnSelect: false
});
```
## Dropdown placement
The `dropdownParent` option allows you to pick an element for the dropdown to be appended to:
```
$('select').select2({
dropdownParent: $('#my_amazing_modal')
});
```
### Using a Select2 control inside a Bootstrap modal
If you're having trouble using the search box inside a Bootstrap modal, trying setting the `dropdownParent` option to the modal element.
## Dropdown option groups
In HTML, `<option>` elements can be grouped by wrapping them with in an `<optgroup>` element:
```
<select>
<optgrouplabel="Group Name">
<option>Nested option</option>
</optgroup>
</select>
```
Select2 will automatically pick these up and render them appropriately in the dropdown.
### Hierarchical options
Only a single level of nesting is allowed per the HTML specification. If you nest an `<optgroup>` within another `<optgroup>`, Select2 will not be able to detect the extra level of nesting and errors may be triggered as a result.
Furthermore, `<optgroup>` elements **cannot** be made selectable. This is a limitation of the HTML specification and is not a limitation that Select2 can overcome.
If you wish to create a true hierarchy of selectable options, use an `<option>` instead of an `<optgroup>` and <ahref="http://stackoverflow.com/q/30820215/359284#30948247">change the style with CSS</a>. Please note that this approach may be considered "less accessible" as it relies on CSS styling, rather than the semantic meaning of `<optgroup>`, to generate the effect.