addOption()
adds a new item into the list of Combobox options
addOption(value: obj | string, join?: boolean): void;
Parameters:
value: obj | string
- required, the value of a new itemjoin: boolean
- optional, if true (by default), adds the new item to the list of options selected in Combobox; if false, only the new item will be selected in Combobox
Example
const combobox = new dhx.Combobox("combo_container", {
multiselection: true
});
combobox.data.parse(dataset);
combobox.setValue([combobox.data.getId(1), combobox.data.getId(3)]);
console.log(combobox.getValue()); // -> u1664261657492,u1664261657494
combobox.addOption("Georgia", false);
console.log(combobox.getValue()); // -> u1664261657520
// check that the new item is added into the data collection
console.log(combobox.data.serialize());
Adding an option as an object
When you need an extended configuration, while adding an item, pass the value parameter as an object with a set of key:value pairs that represent attributes of a Combo option. Check the list of available attributes. For example:
combobox.addOption({
"value": "Austria",
"src": "../common/flags/at.png"
});
Change log:
- The
join
parameter was added in v8.0 - The method was added in v.7.3