Select Field

The select field.

Properties

Title Select
Description A search box field
Field Type select
Base Field Type list

Schema

Property Type Default Description
enum array List of field value options

Options

Property Type Default Description
allowDefaultNoneSelected boolean This is used for required fields, where by default no "None" option is available. Enabling this will allow the none option, and allow it to be initially selected (although this value will be invalid and must be changed before submitting the form)
dataSource string Datasource for generating list of options. This can be a string or a function. If a string, it is considered S be a URI to a service that produces a object containing key/value pairs or an array of elements of structure {'text': '', 'value': ''}. This can also be a function that is called to produce the same list.
emptySelectFirst boolean If the data is empty, then automatically select the first item in the list.
hideNone boolean Whether to hide the None option from a list (select, radio or otherwise). This will be true if the field is required and false otherwise.
join function For multiple select lists. Defines a f(a) for how selected options should be combined into a single string. A split function should also be defined which reverses this function.
multiple boolean Allow multiple selection if true.
multiselect any Multiselect plugin properties - http://davidstutz.github.io/bootstrap-multiselect
name string Field Name.
noneLabel string None The label to use for the 'None' option in a list (select, radio or otherwise).
removeDefaultNone boolean If true, the default 'None' option will not be shown.
size number Number of options to be shown.
sort function Defines an f(a,b) sort function for the array of enumerated values [{text, value}]. This is used to sort enum and optionLabels as well as results that come back from any data sources (for select and radio controls). By default the items are sorted alphabetically. Don't apply any sorting if false.
split function For multiple select lists. Defines a f(a) for how data strings should be split into individual values. A join function should also be defined which reverses this function.
useDataSourceAsEnum boolean true Whether to constrain the field's schema enum property to the values that come back from the data source.

Example 1

Select field with data, options and schema parameters. As default, a select field will be rendered if schema enum property has more than 3 options. The sort order for enumerated values and their text are assumed to be alphanumeric.

{% raw %} {% endraw %}

Example 2

Here is the same select field but labels in French. The important thing to note is that the schema stays the same. The options change, letting you customize forms into different languages.

In addition, we apply a custom sort here using the options.sort override. This lets us plug in a custom sort function. Here we reverse the order.

Note: If you want to disable sorting, set sort to false. Or, if you wish to disable sorting for all of your enumerated fields, set Alpaca.defaultSort to false. See the example below! to false

{% raw %} {% endraw %}

Example 3

Select field with options loaded from external data source.

{% raw %} {% endraw %}

Example 4

Multiple select field with options loaded from external data source.

{% raw %} {% endraw %}

Example 5

Select field with an onField event listener option that reacts to select change event.

{% raw %} {% endraw %}

Example 6

Multiple select field for array data. Note that when using multiple select mode, the hideNone option will default to true.

{% raw %} {% endraw %}

Example 7

Select field in display-only mode

{% raw %} {% endraw %}

Example 8

Multiple select field that works with a local data source file (array of string values).

{% raw %} {% endraw %}

Example 9

Multiple select field that works with a local data source file (array of object values).

{% raw %} {% endraw %}

Example 10

Multiple select field that works with an inline datasource function.

{% raw %} {% endraw %}

Example 11

Multiple select field that works with an inline datasource function.

{% raw %} {% endraw %}

Example 12

A select field that uses the removeDefaultNone option to remove the option for the end user to select None from the list of available options.

Note that if the property that the field describes is required for data integrity to be maintained, consider setting the property schema's required setting to true. This produces the same effect and also allows your data to validate appropriately.

{% raw %} {% endraw %}

Example 13

A select field that is required but which keeps the None option. By default, required fields do not have a None option. Here we set the removeDefaultNone option to false explicitly so that the none option still appears.

This also changes the label from "None" to "-- Select --".

{% raw %} {% endraw %}

Example 14

A multi-select field with numeric selects.

{% raw %} {% endraw %}

Example 15

Here is an example where we explicitly disable sorting. We do this within the field configuration. We could also do this by globally setting Alpaca.defaultSort to false.

{% raw %} {% endraw %}

Example 16

An example where we set the value after render.

{% raw %} {% endraw %}

Example 17

Multiple select field for array data, using custom delimiters.

{% raw %} {% endraw %}