diff --git a/docs/api.md b/docs/api.md index a8b1ec9eb..6dc6d3d63 100644 --- a/docs/api.md +++ b/docs/api.md @@ -1,12 +1,12 @@ ## Selectize API Selectize controls can be controlled programmatically via the methods described in this section. -When initializing the control, the "selectize" property is +When initializing the control, the `selectize` property is added on the original <select> / <input> element—this property points to the underlying Selectize instance. ```js -// initialize the selectize control +// initialize the Selectize control var $select = $('select').selectize(options); // fetch the instance @@ -70,22 +70,25 @@ var selectize = $select[0].selectize;
getAdjacentOption(value, direction)
direction
argument should be 1 for "next" or -1 for "previous".refreshOptions(triggerDropdown)
clear(silent)
silent
is truthy, no change event will be fired on the original input.getItem(value)
addItem(value, silent)
silent
is truthy, no change event will be fired on the original input.removeItem(value, silent)
silent
is truthy, no change event will be fired on the original input.createItem(value, callback)
create
method provided in the Selectize settings 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()
addOptionGroup(id, data)
id
argument refers to a value of the property in option identified by the optgroupField
setting.removeOptionGroup(id)
clearOptionGroups()
removeOptionGroup(id)
clearOptionGroups()
trigger(event, ...)
positionDropdown()
load(fn)
focus()
getValue()
delimiter
if "multiple").setValue(value, silent)
setCaret(index)
index
being the index in the list of selected items).isFull()
clearCache(template)
option
, item
) to clear only that cache.updatePlaceholder()
tokens
string
and regex
.array
items
score
and id
.array
"load"
data
load
option or load
API method)."destroy"
General | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
Option | +Setting | Description | Type | Default | @@ -36,35 +46,29 @@ $(function() {||||||
delimiter |
- The string to separate items by. This option is only used when Selectize is instantiated from a <input type="text"> element. | +The string to separate items by. When typing an item in a multi-selection control allowing creation, then the delimiter, the item is added. If you paste delimiter-separated items in such control, the items are added at once. The delimiter is also used in the getValue API call on a text <input> tag to separate the multiple values. |
string |
',' |
||||||
diacritics |
- Enable or disable international character support. | -boolean |
- true |
- |||||||
create |
- Allows the user to create a new items that aren't in the list of options. This option can be any of the following: "true", "false" (disabled), or a function that accepts two arguments: "input" and "callback". The callback should be invoked with the final data for the option. | -mixed |
+ Allows the user to create new items that aren't in the initial list of options. This setting can be any of the following: boolean|function |
false |
||||||
createOnBlur |
- If true, when user exits the field (clicks outside of input or presses ESC) new option is created and selected (if `create`-option is enabled).
+ If true, when user exits the field (clicks outside of input), a new option is created and selected (if create setting is enabled).
| boolean |
false |
|||||||
createFilter |
- Specifies a RegExp or String containing a regular expression that the current search filter must match to be allowed to be created. May also be a predicate function that takes the filter text and returns whether it is allowed. | -mixed |
+ Specifies a RegExp or a string containing a regular expression that the current search filter must match to be allowed to be created. May also be a predicate function that takes the filter text and returns whether it is allowed.
+ RegExp|string|function |
null |
||||||
maxItems |
- The max number of items the user can select. | +The max number of items the user can select. 1 makes the control mono-selection, null allows an unlimited number of items. | int |
1 |
boolean |
false |
- ||||
closeAfterSelect |
- If true, the dropdown will be closed after a selection is made. | -boolean |
- false |
- |||||||
closeAfterSelect |
+ If true, the dropdown will be closed after a selection is made. | +boolean |
+ false |
+ |||||||
allowEmptyOption |
- If true, Selectize will treat any options with a "" value like normal. This defaults to false to accomodate the common <select> practice of having the first empty option act as a placeholder. | +If true, Selectize will treat any options with a "" value like normal. This defaults to false to accomodate the common <select> practice of having the first empty option to act as a placeholder. | boolean |
false |
||||||
loadThrottle |
- The number of milliseconds to wait before requesting options from the server or null. If null, throttling is disabled. | +The number of milliseconds to wait before requesting options from the server or null. If null, throttling is disabled. Useful when loading options dynamically while the user types a search / filter expression. | int |
300 |
string |
'loading' |
+ ||||
placeholder |
+ The placeholder of the control (displayed when nothing is selected / typed). Defaults to input element's placeholder, unless this one is specified. | +string |
+ undefined |
+ |||||||
preload |
- If true, the "load" function will be called upon control initialization (with an empty search). Alternatively it can be set to "focus" to call the "load" function when control receives focus. | +If true, the load function will be called upon control initialization (with an empty search). Alternatively it can be set to 'focus' to call the load function when control receives focus. |
boolean/string |
false |
||||||
dropdownParent |
- The element the dropdown menu is appended to. This should be "body" or null. If null, the dropdown will be appended as a child of the selectize control. | +The element the dropdown menu is appended to. This should be 'body' or null . If null, the dropdown will be appended as a child of the Selectize control. |
string |
null |
||||||
addPrecedence |
- Sets if the "Add..." option should be the default selection in the dropdown. | +If true, the "Add..." option is the default selection in the dropdown. | boolean |
false |
boolean |
false |
+ ||||
diacritics |
+ Enable or disable international character support. | +boolean |
+ true |
+ |||||||
Data / Searching | ||||||||||
Option | +Setting | Description | Type | Default | ||||||
options |
- Options available to select; array of objects. If your element i as <select> with <option>s specified this property gets populated automatically. Setting this property is convenient if you have your data as an array and want to automatically generate the <option>s. | +See above | +array |
+ [] |
+ ||||||
optgroups |
+ Option groups that options will be bucketed into. If your element is a <select> with <optgroup>s this property gets populated automatically. Make sure each object in the array has a property named whatever optgroupValueField is set to. |
array |
[] |
|||||||
optgroups |
- Option groups that options will be bucketed into. If your element is a <select> with <optgroup>s this property gets populated automatically. Make sure each object in the array has a property named whatever "optgroupValueField" is set to. | -array |
- [] |
- |||||||
dataAttr |
The <option> attribute from which to read JSON data about the option. | @@ -186,7 +206,7 @@ $(function() {|||||||||
valueField |
- The name of the property to use as the "value" when an item is selected. | +The name of the property to use as the value when an item is selected. |
string |
'value' |
||||||
sortField |
- A single field or an array of fields to sort by. Each item in the array should be an object containing at
- least a "field" property. Optionally, "direction" can be set to "asc" or "desc". The
- order of the array defines the sort precedence. + A single field or an array of fields to sort by. Each item in the array should be an object containing at least a - + Unless present, a special `$score` field will be automatically added to the beginning of the sort list. This will make results sorted primarily by match quality (descending). - You can override the "$score" function. For more information, see the sifter documentation. +You can override the `$score` function. For more information, see the sifter documentation. |
string|array |
'$order' |
@@ -238,19 +254,19 @@ $(function() {
|||||||
searchConjunction |
- When searching for multiple terms (separated by a space), this is the operator used. Can be "and" or "or". | +When searching for multiple terms (separated by space), this is the operator used. Can be 'and' or 'or' . |
string |
'and' |
||||||
lockOptgroupOrder |
- If truthy, selectize will make all optgroups be in the same order as they were added (by the "$order" property). Otherwise, it will order based on the score of the results in each. | +If truthy, Selectize will make all optgroups be in the same order as they were added (by the `$order` property). Otherwise, it will order based on the score of the results in each. | boolean |
false |
||||||
copyClassesToDropdown |
- Copy the original input classes to the Dropdown element. | +Copy the original input classes to the dropdown element. | boolean |
true |
Callbacks | |||||
Option | +Setting | Description | Type | Default | ||||||
load(query, callback) |
- Invoked when new options should be loaded from the server. | +Invoked when new options should be loaded from the server. Called with the current query string and a callback function to call with the results when they are loaded (or nothing when an error arises). | function |
null |
||||||
score(search) |
- Overrides the scoring function used to sort available options. The provided function should return a function that returns a number greater than or equal to zero to represent the "score" of an item (the function's first argument). If 0, the option is declared not a match. The "search" argument is a Search object. For an example, see the "GitHub" example. | +Overrides the scoring function used to sort available options. The provided function should return a function that returns a number greater than or equal to zero to represent the score of an item (the function's first argument). If 0, the option is declared not a match. The search argument is a Search object. For an example, see the "GitHub" example. |
function |
null |
function |
null |
- ||||
onFocus() |
- Invoked when the control gains focus. | -function |
- null |
- |||||||
onBlur() |
- Invoked when the control loses focus. | -function |
- null |
- |||||||
onFocus() |
+ Invoked when the control gains focus. | +function |
+ null |
+ |||||||
onBlur() |
+ Invoked when the control loses focus. | +function |
+ null |
+ |||||||
onChange(value) |
Invoked when the value of the control changes. | @@ -355,7 +371,7 @@ $(function() {|||||||||
onLoad(data) |
- Invoked when new options have been loaded and added to the control (via the "load" option or "load" API method). | +Invoked when new options have been loaded and added to the control (via the load option or load API method). |
function |
null |
||||||
render |
- Custom rendering functions. Each function should accept two arguments: "data" and "escape" and return HTML (string) with a single root element.
- The "escape" argument is a function that takes a string and escapes all special HTML characters.
+ Custom rendering functions. Each function should accept two arguments: data and escape and return HTML (string) with a single root element.
+ The escape argument is a function that takes a string and escapes all special HTML characters.
This is very important to use to prevent XSS vulnerabilities.
-
|