Currently when the editor field plugin for Select2 creates an option there is no way to define the class. I came across this issue when looking at How to pass <option> attributes to select2. I made a simple change to editor.select2.js
to make this possible, see addClass()
addition below:
success: function (json) {
var addOption = function (option) {
if (conf._input.find('option[value="' + option.id + '"]').length === 0) {
$('<option/>')
.attr('value', option.id)
.text(option.text)
.addClass( typeof conf.optionClass === 'function' ? conf.optionClass(option) : null )
.appendTo(conf._input);
}
}
...
}
When using with an ajax data source the item in the returned object can be used to determine the class in the editor options (see below). This works well for me and I think other users would find this useful too. I noticed that editor.select2.js
isn't in GitHub, is it possible to merge this change into your editor repo?
optionClass: function (json) {
return json.deleted ? 'deleted' : null;
}