Skip to content

Latest commit

 

History

History
178 lines (170 loc) · 6.38 KB

api.md

File metadata and controls

178 lines (170 loc) · 6.38 KB

Selectize API

Selectize controls can be controlled programmatically via the methods described in this section. When initializing the control, the "selectize" property is added on the original <select> / <input> element—this property points to the underlying Selectize instance.

// initialize the selectize control
var $select = $('select').selectize(options);

// fetch the instance
var selectize = $select[0].selectize;

Methods

Options
Method Description
addOption(value, data) Adds an available option. If it already exists, nothing will happen. Note: this does not refresh the options list dropdown (use refreshOptions() for that).
updateOption(value, data) Updates an option available for selection. If it is visible in the selected items or options dropdown, it will be re-rendered automatically.
removeOption(value) Removes the option identified by the given value.
getOption(value) Retrieves the data for the option identified by the given value.
refreshOptions(triggerDropdown) Refreshes the list of available options shown in the autocomplete dropdown menu.
Items
Method Description
clear() Resets / clears all selected items from the control.
getItem(value) Returns the jQuery element of the item matching the given value.
addItem(value) "Selects" an item. Adds it to the list at the current caret position.
removeItem(value) Removes the selected item matching the provided value.
createItem(value) Invokes the "create" method provided in the selectize options that should provide the data for the new item, given the user input. Once this completes, it will be added to the item list.
refreshItems() Re-renders the selected item lists.
Search
Method Description
getScoreFunction(search) Returns a function for scoring individual options. This should only be used within the "score" callback provided in the options. Returns a float.
Dropdown
Method Description
open() Shows the autocomplete dropdown containing the available options.
close() Closes the autocomplete dropdown menu.
positionDropdown() Calculates and applies the appropriate position of the dropdown.
Other
Method Description
focus() Brings the control into focus.
blur() Forces the control out of focus.
lock() Disables user input on the control.
unlock() Re-enables user input on the control.
getValue() Returns the value of the control. If multiple items can be selected (e.g. <select multiple>), this returns an array. If only one item can be selected, this returns a string.
setValue(value) Resets the selected items to the given value.
setCaret(index) Moves the caret to the specified position ("index" being the index in the list of selected items).
isFull() Returns whether or not the user can select more items.

Related Objects

Search

Option Description Type
query The raw user input. string
tokens An array containing parsed search tokens. A token is an object containing two properties: "string" and "regex". array
total The total number of results. int
items A list of matched results. Each result is an object containing two properties: "score" and "value". array