Function select

SELECT element.

Handle changes in value:

const mySelect = select(`#mySelect`, (newValue) => {
console.log(`Value is now ${newValue}`);
});

Enable/disable:

mySelect.disabled = true / false;

Get currently selected index or value:

mySelect.value / mySelect.index

Is the currently selected value a placeholder?

mySelect.isSelectedPlaceholder

Set list of options

// Adds options, preselecting `opt2`.
mySelect.setOpts([`opt1`, `opt2 ...], `opt2`);

Select an element

mySelect.select(1); // Select second item
mySelect.select(1, true); // If true is added, change handler fires as well
  • Parameters

    • domQueryOrEl: string | HTMLSelectElement

      Query (eg #id) or element

    • OptionalonChanged: ((currentValue: string) => void)

      Callback when a selection is made

        • (currentValue): void
        • Parameters

          • currentValue: string

          Returns void

    • options: SelectOpts = {}

      Options

    Returns SelectHandler