Table Of Contents

Application Packaging Standard

Last updated 18-Mar-2019

aps/Select

Analogue to the HTML select element.

Compatibility

All user panels - CP and UX1

Overview

Structure

The aps/Select widget is a modified analog to the select HTML element.

Find the nested rules for this widget in the recommended Widget Hierarchy.

An option in a drop-down list is described by an object which may contain the following set of properties:

  • label

    Text to be displayed above the drop-down list.

  • value

    Option value.

  • selected

    If the value of this property is true, then this option will be selected.

  • disabled

    If the value of this property is true, then this option will be unavailable for selection.

Usage

You may define a set of options for a drop-down list either using an array of objects passed during widget creation in the options property, or with help of a local store defined by the store property or using the setStore method. The name of record property for the store, from which it is necessary to take data, is defined by the labelAttr widget property. References to nested properties through dot are supported. For example: “lbl.name”. The default value of the property equals “label”.

Warning

If you use the declarative approach when creating a widget, then you should use the <select> tag to ensure IE8 will correctly process the widget.

<select id="Declarative" data-dojo-type="aps/Select">
   <option value="Tennessee">TN</option>
   <option value="Virginia" selected="selected">VA</option>
   <option value="Washington" disabled>WA</option>
   <option value="Florida" disabled>FL</option>
   <option value="California">CA</option>
 </select>

In the simplest case, just describe an options object when creating a widget.

Simple example

RUN DEMO

require(["aps/load", "aps/ready!"],
function(load){
    "use strict";

    load(["aps/PageContainer", [
        ["aps/Panel", [
            ["aps/FieldSet", [
                ["aps/Select", {
                    label: "Select a state",
                    options: [
                        { value: "TN", label: "Tennessee" },
                        { value: "VA", label: "Virginia", selected: true },
                        { value: "WA", label: "Washington", disabled: true },
                        { value: "FL", label: "Florida" },
                        { value: "CA", label: "California" }
    ]}]]]]]]]);
});

After the widget is created, you can modify the set of options using the following methods:

  • addOption

    The method adds to a widget an option created on basis of the object passed to the method.

  • removeOption

    The method removes the specified options. It may accept as the argument an option value, option number or an array of option values and/or numbers.

  • updateOption

    The method changes the specified options. It may accept as the argument an object describing the option or an array of such objects.

There is also a getOption method using which you can get a description of one or several options. It may accept as the argument the option value, option ordinal number or an array of values and/or ordinal numbers of the required options.

Examples

Using Options

RUN DEMO

require(["aps/Select", "aps/FieldSet", "aps/Panel", "aps/PageContainer", "aps/ready!"],
function(Select, FieldSet, Panel, PageContainer){
    "use strict";

    var sel =
    new Select({
        options: [ { label: "TN", value: "Tennessee" },
            { label: "VA", value: "Virginia",   selected: true },
            { label: "WA", value: "Washington", disabled: true },
            { label: "FL", value: "Florida" },
            { label: "CA", value: "California"
    }]});

    var page = new PageContainer();
    page.placeAt("modifyOptionsDiv");
    var panel = new Panel();
    var fieldset = new FieldSet();
    fieldset.addChild(sel);
    panel.addChild(fieldset);
    page.addChild(panel);

    sel.addOption({ label: "SPb", value: "Saint-Petersburg", selected: true });
    sel.removeOption("Tennessee");
    sel.removeOption(2);
    sel.removeOption(["Florida", 1]);
    sel.updateOption([
        { label: "House", value: "Saint-Petersburg", selected: true },
        { label: "FLY", value: "Florida" }
    ]);
    sel.updateOption({   label: "CF",   value: "California" });
});

Using Store

You may define a set of options using a store component. The best choice is to use a local store module dojo/store/Memory. For details, see Model.

You may define a store for the widget using the store property or the setStore method.

Note

When defining options using a store, the id property provides the value of an option being created and not the value property. This must be taken into account when using the updateOption and removeOption methods.

RUN DEMO

require(["aps/Select", "aps/FieldSet", "aps/Panel", "aps/Memory", "aps/PageContainer", "aps/ready!"],
function(Select, FieldSet, Panel, Memory, PageContainer){
    "use strict";

    var store = new Memory({ data: [
        { value: "foo", label: "Foo" },
        { value: "bar", label: "Bar" }
    ]});

    var page = new PageContainer();
    page.placeAt("storeSelectDiv");
    var fieldset = new FieldSet();
    var panel = new Panel();

    fieldset.addChild(new Select({
        id:         "storeSelect",
        name:       "storeSelect",
        store:      store,
        labelAttr:  "label",
        label:      "Store Select example"
    }));
    panel.addChild(fieldset);
    page.addChild(panel);
    page.startup();
});

Public Properties

PROPERTY TYPE DEFAULT DESCRIPTION
autoSize boolean false Only for PCP / CCP v1.
description string “” Textual description to be displayed as a small greyed text under the control.
disabled boolean false Specifies if the widget will respond to user input.
gridSize string undefined This specifies the widget width that is relevant only for widgets inside Container, FieldSet, or Tiles.
hint string “” Help information in a widget.
isBusy boolean false If the widget is busy then this property is true.
label string “” Text that is shown as a label if the widget is placed inside a aps/FieldSet.
labelAttr string label Specifies which attribute from the ``store`` entries will be displayed in the drop-down list.
missingMessage string This value is required. The message to display if value is empty and the field is required.
optionalText string (Optional) Text for optional widgets of the Input category.
options array null Array of possible values.
placeHolder string “” Grayed out initial string in a field.
required boolean false User is required to enter data in the input field.
size number 10 - PCP / CCP v1, undefined - CCP v2 Affects the selection of a CSS class that defines the width of the input field of the widget.
visible boolean true If this property value is set to true, then the widget is visible.

autoSize boolean

Only for PCP / CCP v1. If this property value is set to “true”, then a CSS class is assigned to the widget based on the value of the “size” property: size <= 7 - f-small-size (40px) 7 < size <= 33 - f-middle-size (215px) 33 < size - f-big-size (240px) The default value of this property is false. If you want to use your own CSS class for defining the widget’s size, you should set this property value to “false” and specify your class name in the widget’s “class” property.

description string

Textual description to be displayed as a small greyed text under the control. Default value: “”.

disabled boolean

Specifies if the widget will respond to user input.

Default value: false.

gridSize string

This specifies the widget width that is relevant only for widgets inside Container, FieldSet, or Tiles. In other cases it will be ignored.

gridSize string contains few options with number values (from 1 to 12) separated by spaces, which specify the grid size of the widget in different layouts:

- md - desktop

- xs - phone

For example, gridSize: “md-4 xs-2”.

All values below 1, e.g. “md-0”, will be replaced with the empty string (“”), values above 12, e.g. “md-14”, will be reduced to 12 (“md-12”).

Default value: undefined.

hint string

Help information in a widget. It is shown under the content of the widget. Deprecated in CCP v2. Default value: “”.

isBusy boolean

If the widget is busy then this property is true.

Default value: false.

label string

Text that is shown as a label if the widget is placed inside a aps/FieldSet.

Default value: “”.

labelAttr string

Specifies which attribute from the ``store`` entries will be displayed in the drop-down list. This is a mandatory property when the ``store`` is used. Default value: “label”.

missingMessage string

The message to display if value is empty and the field is required. The translated string value is read from the message file by default. Default value: “This value is required.”

optionalText string

Text for optional widgets of the Input category. Default value: “(Optional)”.

options array

Array of possible values. Default value: null.

placeHolder string

Grayed out initial string in a field. For example, it can display instructions. Default value: “”.

required boolean

User is required to enter data in the input field. Default value: false.

size number

Affects the selection of a CSS class that defines the width of the input field of the widget. See the specification for more details.

size <= 7        f-small-size (40px)
7 < size <= 33   f-middle-size (215px)
size > 33        f-big-size (240px)

Default value: 10 - PCP / CCP v1, undefined - CCP v2.

visible boolean

If this property value is set to true, then the widget is visible.

Default value: true.

Public Methods

METHOD RETURN DESCRIPTION
addOption (option)
aps.select
Addition Option
cancel ()
object
Sets the isBusy property to false
destroy ()
undefined
Destroy this widget
extraValidator ()
boolean
Here, you can do additional verifications
focus ()
aps/select
function
Focusing on the focusNode of the current object
get ()
any
Get a property of the Stateful instance
getCustomErrorMessage ()
string
Here, you can return a custom error message
getOption (valueOrIdx)
object|array
Get Option(s)
getParents ()
array
Discover and return all parents of the widget
placeAt ()
dijit/_widgetbase
function
Place this widget somewhere in the DOM based on standard dojo/dom-construct::place() conventions
removeOption (valueOrIdx)
aps.select
Remove Option
reset ()
undefined.
Resets the widget’s value to what it was at initialization time
set ()
object
function
Set a property of the Stateful instance
setStore (store)
dojo.store
Change store
startup ()
undefined
Processing after the DOM fragment is added to the document
updateOption (options)
aps.select
Update Option
validate ()
boolean
Called by oninit, onblur, and onkeypress

addOption

Addition Option

Return: aps.select

ARGUMENT TYPE DESCRIPTION
option
Object
New option

cancel

Sets the isBusy property to false.

Return: object

destroy

Destroy this widget. Will also destroy any resources (including widgets) registered via this.own(). This method will also destroy internal widgets such as those created from a template.

Return: undefined

extraValidator

Here, you can do additional verifications.

Return: boolean

focus

Focusing on the focusNode of the current object

Return: aps/select function

get

Get a property of the Stateful instance. Get a named property of the Stateful object. The property may potentially be retrieved via a getter method in subclasses.

In the base class, this just retrieves the object’s property.

Return: any

getCustomErrorMessage

Here, you can return a custom error message. The method must return a value, only if additional verifications fail. To change standard error messages, use respective properties.

Return: string

getOption

Get Option(s)

Return: object|array

ARGUMENT TYPE DESCRIPTION
valueOrIdx
String
Number
Array
Value Option or number Option or array of numbers or array of values

getParents

Discover and return all parents of the widget.

Return: array

placeAt

Place this widget somewhere in the DOM based on standard dojo/dom-construct::place() conventions. A convenience function providing a simple shorthand mechanism to put an existing (or newly created) widget somewhere in the DOM, and allow chaining.

Return: dijit/_widgetbase function

removeOption

Remove Option

Return: aps.select

ARGUMENT TYPE DESCRIPTION
valueOrIdx
String
Number
Array
Value Option or number Option or array of numbers or array of values

reset

Resets the widget’s value to what it was at initialization time.

Return: undefined.

set

Set a property of the Stateful instance. Sets named properties of the stateful object and notifies the watchers of the property. A programmatic setter may be defined in subclasses.

Return: object function

setStore

Change store

Return: dojo.store

ARGUMENT TYPE DESCRIPTION
store
dojo.Store
New store

startup

Processing after the DOM fragment is added to the document. Called after a widget and its children have been created and added to the page and all related widgets have finished their creation cycle, that is after the postCreate() function is successfully completed for each of the related widgets. Note that startup() may be called while the widget is still hidden.

Return: undefined

updateOption

Update Option

Return: aps.select

ARGUMENT TYPE DESCRIPTION
options
Object
Array
Option or array of options

validate

Called by oninit, onblur, and onkeypress. Show missing or invalid messages if appropriate, and highlight textbox field.

Return: boolean

Public Events

EVENT RETURN DESCRIPTION
onClick ()
undefined
The method is called when a user clicks on the widget

onClick

The method is called when a user clicks on the widget.