0

I have a lightning component which generates picklist values from a map. How do I pass the selected value from the lightning select to the controller.

I have the following but get: undefined on selection

Component

<aura:component controller="SampleAuraController">
    <aura:attribute name="mapValues" type="object" /> 
  <aura:handler name="init" value="{!this}" action="{!c.getMapValues}"/>
            <lightning:select aura:id="select"  name="selectItem" label="Select an item" variant="label-hidden" onchange="{!c.handleChange}" value="{!v.mapValue}" >
                <option value="">choose one...</option>
                <aura:iteration items="{!v.mapValues}"  var="mapKey" indexVar="key">  
                    <!--  <strong><p>{!mapKey.key}</p></strong>-->
                    <aura:iteration items="{!mapKey.value}" var="mapValue">
                        <option>{!mapValue}</option>
                    </aura:iteration>       
                </aura:iteration>
            </lightning:select>
</aura:component>

Controller

 handleChange: function (cmp, event, helper) {
    alert(event.getParam('mapValue'));
}

1 Answer 1

2

You can define a client-side controller action to handle various input events on the dropdown list. For example, to handle a change event on the component, use the onchange attribute. Retrieve the selected value using cmp.find("select").get("v.value").

See the below code, where select is the aura:id of the lightning:select.

handleChange: function (cmp, event, helper) {
    alert(cmp.find("select").get("v.value"));
}

Documentations

You must log in to answer this question.

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