Disabling an option in an optgroup doesn't work for a select2 initialised with a data array.
Author: jrcheneryCreated Dec 11, 2025Updated May 26, 2026
Labelsconfirmed bug4.xfeature: dropdown
Setting the disabled attribute on an option created from data that is not grouped disables the option in the select2 dropdown as expected. If the data is grouped and the option is inside an optgroup the option is not shown as disabled in the select2.
Steps to reproduce:
- Initialise a select2 using a data array which contains grouped data
- Set the disabled html attribute on one of the options
- Option is not disabled in the select2
I've created a fiddle which shows the difference in behaviour with ungrouped and grouped data: https://jsfiddle.net/tew29Lpd/ The Disable button should disable 'Option 2' in both selects but it does not in the one with optgroups.
Using version 4.0.13, in Chrome and Firefox
Source: select2/select2