2

Hi i am unable to get ui:inputSelectOption value in js. I have values in v.accListwhich is of type Account[]. In alert its getting as undefined.

CMP

      <ui:inputSelect aura:id="acc" required="true">                        
           <aura:iteration items="{!v.accList}" var="ac">
               <ui:inputSelectOption text="{!ac.Id}" label="{!ac.Name}"/>
           </aura:iteration>
      </ui:inputSelect>

JS

 alert('getaccValue'+(component.find("acc").get("v.text")));

2 Answers 2

4

ui:inputSelect stores the selected text's in value attribute.

You have to specify when you want to retrieve selected Accounts. In my example, it is the change Event Attribute.

Component

<aura:attribute name="selectedAccounts" type="String" />

<ui:inputSelect value="{!v.selectedAccounts}" change="{!c.onAccountChange}">                        
    <aura:iteration items="{!v.accList}" var="ac">
        <ui:inputSelectOption text="{!ac.Id}" label="{!ac.Name}"/>
    </aura:iteration>
</ui:inputSelect>

Controller

onAccountChange: function(component) {
    console.log('Selected Accounts: ', component.get('v.selectedAccounts'));
}

Mind that selectedAccounts will store text's attributes value. Multiple selected values are separated by ;.

1
  • 1
    Welcome to SFSE!
    – sfdcfox
    Jun 25, 2017 at 18:11
0

Providing a simple example of ui:Inputselect

component:

<aura:attribute name="contactLevel" type="String[]" default="Primary Contact, Secondary Contact, Other"/>
    <ui:inputSelect aura:id="levels" label="Contact Levels" change="{!c.onSelectChange}">
        <aura:iteration items="{!v.contactLevel}" var="level">
             <ui:inputSelectOption text="{!level}" label="{!level}"/>
        </aura:iteration>
    </ui:inputSelect>

Helper:

onSelectChange : function(component,event) {
      var selected = component.find("levels").get("v.value");
        alert(selected);
    }

if you look at the helper code i get the select value using the input select attribute 'v.value'.

in your case can you modify the below line to v.value instead of v.text

alert('getaccValue'+(component.find("acc").get("v.value")));

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .