# new Select(config, optionsFilteropt)
Its a Custom Web Component. Do not use the constructor directly with the new keyword. Instead, use one of the 3 following methods:
Create the Web Component and call its init method:
const mySelect = document.createElement("a-select").init(config)
Or use the shorthand for it:
const mySelect = createSelect({
label: "Countries",
options: [
{value: "France"},
{value: "Great Britain"}
]
})
mySelect.render()
Or directly declare the config inside a container component:
const myPanel = createPanel({
title: "My panel",
items: [
{
type: "select",
options: [
{value: "France"},
{value: "Great Britain"}
]
}
]
})
myPanel.render()
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
config |
object
|
||
template |
object
|
"time" - TODO: other template like "range" | "weekday" | "month" | ... |
|
options |
Array.<string>
|
Array.<object>
|
function
|
List of options or function that returns a list of options, where each option must a string, or an object like:
|
|
optionsFilter |
function
|
<optional> |
When the options are defined by a function, you can provide a filtering function that will be executed at runtime to filter only a specific set of options, depending on the context |
config.multiple |
boolean
|
<optional> |
True to enable multi-select |
config.value |
string
|
Array.<string>
|
<optional> |
Default value |
config.optionsColor |
string
|
<optional> |
Default color for all options |
config.valueSeparator |
string
|
<optional> |
Character used to display multiple values |
config.inputSeparator |
string
|
<optional> |
Character used to input multiple values |
config.stackValues |
boolean
|
<optional> |
True to render the values one on another |
config.hideInput |
boolean
|
<optional> |
true (default) to automatically hide the input field after a completed search |
config.allowValuesNotInList |
boolean
|
<optional> |
Allow to input a value which is not in the list of options |
config.allowDuplicates |
boolean
|
<optional> |
Allow to input duplicate values. Default to false. |
config.allowClickToDelete |
boolean
|
<optional> |
Add a "cross" icon over the values to delete them. Default to false. |
config.allowSwitchOnOff |
boolean
|
<optional> |
Allow to click on a value to switch it on/off |
config.optionRenderer |
function
|
<optional> |
Custom function to render each option in the list of options |
config.valueRenderer |
function
|
<optional> |
Custom function to render the actual field values |
config.label |
string
|
<optional> |
|
config.fieldWidth |
string
|
<optional> |
|
config.labelWidth |
string
|
<optional> |
|
config.labelPosition |
string
|
<optional> |
left | right | top | bottom |
config.labelAlign |
string
|
<optional> |
left | right |
config.autocomplete |
boolean
|
<optional> |
Set "off" to disable |
config.readOnly |
boolean
|
<optional> |
|
config.disabled |
boolean
|
<optional> |
|
config.required |
boolean
|
<optional> |
|
config.validationFunction |
function
|
<optional> |
Async function that must return true if the value is valid, false otherwise |
config.margin |
string
|
<optional> |
|
config.padding |
string
|
<optional> |
|
config.display |
string
|
<optional> |
flex | inline flex |
config.width |
string
|
number
|
<optional> |
|
config.height |
string
|
number
|
<optional> |
this
Generated markup
The field is a composition of various elements:
- a div for the field label
- a div that renders the existing values (as chips, by default)
- an input field, used to filter options
- a div to display and select the options
<a-select class="a-select">
<label class="field-label"></label>
<div class="field-select">
<span class="field-select-values"></span>
</div>
<div class="field-select-options">
<span class="field-select-input"></span>
<!-- For each option -->
<div class="field-option"></div>
</div>
</a-select>
Methods
# async addValue(newValue)
Add a value to the Select field. This method does a few things:
- check for duplicate entries (and remove if not allowed)
- check for multiple entries (and exit if not allowed)
- update the field value
- reset the input field then give it focus
Parameters:
Name | Type | Description |
---|---|---|
newValue |
string
|
Value to add |
# getSelection() → {object|Array.<object>}
Get the selected option(s)
A single option or an array of options if multiple values are selected
object
|
Array.<object>
# getValue() → {string|Array.<string>}
Get the field value
- Returns an array of strings if the "multiple" option is true. Returns a string otherwise.
string
|
Array.<string>
# setClickToDelete(state)
Allow/forbid to click on field values to delete them
Parameters:
Name | Type | Default | Description |
---|---|---|---|
state |
boolean
|
true |
# setLabelPosition(position)
Set label position
Parameters:
Name | Type | Description |
---|---|---|
position |
string
|
"left" (default) | "right" | "top" | "bottom" |
this
# setMultiple(state)
Allow/forbid to select multiple values
Parameters:
Name | Type | Default | Description |
---|---|---|---|
state |
boolean
|
true |
# setValue(newValue, rawUpdateopt)
Set the field value
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
newValue |
string
|
Array.<string>
|
The new field value |
|
rawUpdate |
boolean
|
<optional> |
If true, it doesn't update the associated record and doesn't trigger "change" event |
this
# sort(order)
Sort values
Parameters:
Name | Type | Default | Description |
---|---|---|---|
order |
string
|
asc | "asc" or "desc" |
this
# sortByLabel(order)
Sort values according to their corresponding label
Parameters:
Name | Type | Default | Description |
---|---|---|---|
order |
string
|
asc | "asc" or "desc" |
this
# updateOptions(newOptions)
Update the list of options
Parameters:
Name | Type | Description |
---|---|---|
newOptions |
array
|
An array of object defining the field options |
Example
mySelectField.updateOptions([
{
value: "firstName",
disabled: false,
color: "#00aaee"
},
{...}
])