Skip to main content

addOption()

adds a new item into the list of Combobox options

addOption(value: string, join?: boolean): void;

Parameters:

  • value: string - required, the value of a new item
  • join: 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());
note

The method invokes the beforeAdd and afterAdd events of the Data Collection object. If the beforeAdd event returns false, a new item won't be added into the data collection.

Change log:

  • The join parameter was added in v8.0
  • The method was added in v.7.3