Newer Version Available
ui:inputSelect
A ui:inputSelect component is rendered as an HTML select element. It contains options, represented by the ui:inputSelectOption components. To enable multiple selections, set multiple="true". To wire up any client-side logic when an input value is selected, use the change event.
1<ui:inputSelect multiple="true">
2 <ui:inputSelectOption text="All Primary" label="All Contacts" value="true"/>
3 <ui:inputSelectOption text="All Primary" label="All Primary"/>
4 <ui:inputSelectOption text="All Secondary" label="All Secondary"/>
5</ui:inputSelect>v.value represents the option's HTML selected attribute, and v.text represents the option's HTML value attribute.
Generating Options with aura:iterationYou can use aura:iteration to iterate over a list of items to generate options. This example iterates over a list of items and handles the change event.
1<aura:attribute name="contactLevel" type="String[]" default="Primary Contact, Secondary Contact, Other"/>
2 <ui:inputSelect aura:id="levels" label="Contact Levels" change="{!c.onSelectChange}">
3 <aura:iteration items="{!v.contactLevel}" var="level">
4 <ui:inputSelectOption text="{!level}" label="{!level}"/>
5 </aura:iteration>
6 </ui:inputSelect>When the selected option changes, this client-side controller retrieves the new text value.
1onSelectChange : function(component, event, helper) {
2 var selected = component.find("levels").get("v.value");
3 //do something else
4}Generate the options dynamically on component initialization using a controller-side action.
1<aura:component>
2 <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
3 <ui:inputSelect label="Select me:" class="dynamic" aura:id="InputSelectDynamic"/>
4</aura:component>The following client-side controller generates options using the options attribute on the ui:inputSelect component. v.options takes in the list of objects and converts them into list options. The opts object constructs InputOption objects to create the ui:inputSelectOptions components within ui:inputSelect. Although the sample code generates the options during initialization, the list of options can be modified anytime when you manipulate the list in v.options. The component automatically updates itself and rerenders with the new options.
1({
2 doInit : function(cmp) {
3 var opts = [
4 { class: "optionClass", label: "Option1", value: "opt1", selected: "true" },
5 { class: "optionClass", label: "Option2", value: "opt2" },
6 { class: "optionClass", label: "Option3", value: "opt3" }
7
8 ];
9 cmp.find("InputSelectDynamic").set("v.options", opts);
10 }
11})class is a reserved keyword that might not work with older versions of Internet Explorer. We recommend using "class" with double quotes. If you’re reusing the same set of options on multiple drop-down lists, use different attributes for each set of options. Otherwise, selecting a different option in one list also updates other list options bound to the same attribute.
1<aura:attribute name="options1" type="String" />
2<aura:attribute name="options2" type="String" />
3<ui:inputSelect aura:id="Select1" label="Select1" options="{!v.options1}" />
4<ui:inputSelect aura:id="Select2" label="Select2" options="{!v.options2}" />This example displays a drop-down list with single and multiple selection enabled, and another with dynamically generated list options. It retrieves the selected value of a ui:inputSelect component.
1<aura:component>
2<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
3
4<div class="row">
5<p class="title">Single Selection</p>
6<ui:inputSelect class="single" aura:id="InputSelectSingle" change="{!c.onSingleSelectChange}">
7
8 <ui:inputSelectOption text="Any"/>
9 <ui:inputSelectOption text="Open" value="true"/>
10 <ui:inputSelectOption text="Closed"/>
11 <ui:inputSelectOption text="Closed Won"/>
12 <ui:inputSelectOption text="Prospecting"/>
13 <ui:inputSelectOption text="Qualification"/>
14 <ui:inputSelectOption text="Needs Analysis"/>
15 <ui:inputSelectOption text="Closed Lost"/>
16 </ui:inputSelect>
17 <p>Selected Item:</p>
18 <p><ui:outputText class="result" aura:id="singleResult" value="" /></p>
19</div>
20
21<div class="row">
22 <p class="title">Multiple Selection</p>
23 <ui:inputSelect multiple="true" class="multiple" aura:id="InputSelectMultiple" change="{!c.onMultiSelectChange}">
24
25 <ui:inputSelectOption text="Any"/>
26 <ui:inputSelectOption text="Open"/>
27 <ui:inputSelectOption text="Closed"/>
28 <ui:inputSelectOption text="Closed Won"/>
29 <ui:inputSelectOption text="Prospecting"/>
30 <ui:inputSelectOption text="Qualification"/>
31 <ui:inputSelectOption text="Needs Analysis"/>
32 <ui:inputSelectOption text="Closed Lost"/>
33
34 </ui:inputSelect>
35 <p>Selected Items:</p>
36 <p><ui:outputText class="result" aura:id="multiResult" value="" /></p>
37</div>
38
39<div class="row">
40 <p class="title">Dynamic Option Generation</p>
41 <ui:inputSelect label="Select me: " class="dynamic" aura:id="InputSelectDynamic" change="{!c.onChange}" />
42 <p>Selected Items:</p>
43 <p><ui:outputText class="result" aura:id="dynamicResult" value="" /></p>
44</div>
45
46</aura:component>1({
2 doInit : function(cmp) {
3 // Initialize input select options
4 var opts = [
5 { "class": "optionClass", label: "Option1", value: "opt1", selected: "true" },
6 { "class": "optionClass", label: "Option2", value: "opt2" },
7 { "class": "optionClass", label: "Option3", value: "opt3" }
8
9 ];
10 cmp.find("InputSelectDynamic").set("v.options", opts);
11
12 },
13
14 onSingleSelectChange: function(cmp) {
15 var selectCmp = cmp.find("InputSelectSingle");
16 var resultCmp = cmp.find("singleResult");
17 resultCmp.set("v.value", selectCmp.get("v.value"));
18 },
19
20 onMultiSelectChange: function(cmp) {
21 var selectCmp = cmp.find("InputSelectMultiple");
22 var resultCmp = cmp.find("multiResult");
23 resultCmp.set("v.value", selectCmp.get("v.value"));
24 },
25
26 onChange: function(cmp) {
27 var dynamicCmp = cmp.find("InputSelectDynamic");
28 var resultCmp = cmp.find("dynamicResult");
29 resultCmp.set("v.value", dynamicCmp.get("v.value"));
30 }
31
32})Attributes
| Attribute Name | Attribute Type | Description | Required? |
|---|---|---|---|
| body | Component[] | The body of the component. In markup, this is everything in the body of the tag. | |
| class | String | A CSS style to be attached to the component. This style is added in addition to base styles output by the component. | |
| disabled | Boolean | Specifies whether the component should be displayed in a disabled state. Default value is "false". | |
| label | String | The text of the label component | |
| labelClass | String | The CSS class of the label component | |
| multiple | Boolean | Specifies whether the input is a multiple select. Default value is “false”. | |
| options | List | A list of aura.components.ui.InputOption. | |
| required | Boolean | Specifies whether the input is required. Default value is "false". | |
| requiredIndicatorClass | String | The CSS class of the required indicator component | |
| updateOn | String | Updates the component's value binding if the updateOn attribute is set to the handled event. Default value is "change". | |
| value | String | The value currently in the input field. |
Events
| Event Name | Event Type | Description |
|---|---|---|
| dblclick | COMPONENT | Indicates that a component has been double-clicked. |
| mouseover | COMPONENT | Indicates that the user has moved the mouse pointer over the component. |
| mouseout | COMPONENT | Indicates that the user has moved the mouse pointer away from the component. |
| mouseup | COMPONENT | Indicates that the user has released the mouse button. |
| mousemove | COMPONENT | Indicates that the user has moved the mouse pointer. |
| click | COMPONENT | Indicates that a component has been clicked. |
| mousedown | COMPONENT | Indicates that the user has pressed a mouse key. |
| select | COMPONENT | Indicates that the user has made a selection. |
| blur | COMPONENT | Indicates that a component has been put out of focus. |
| focus | COMPONENT | Indicates that a component has been put on focus. |
| keypress | COMPONENT | Indicates that the user has pressed and held down a keyboard key. |
| keyup | COMPONENT | Indicates that the user has released a keyboard key. |
| keydown | COMPONENT | Indicates that the user has pressed and released a keyboard key. |
| cut | COMPONENT | Indicates that the user has cut content to the clipboard. |
| validationError | COMPONENT | Indicates that the component has validation error(s). |
| clearErrors | COMPONENT | Indicates that any validation error should be cleared. |
| change | COMPONENT | Indicates that the content of a component or the state has changed. |
| copy | COMPONENT | Indicates that the user has copied content to the clipboard. |
| paste | COMPONENT | Indicates that the user has pasted content from the clipboard. |