+ Start a Discussion
Ryan MeyerRyan Meyer 

Lightning select onchange not triggering

Beating my head against the wall and hoping someone can point out what I'm missing. I have a basic Lightning component with a drop-down. When that drop-down changes, I'd like the controller to make a second field visible through an aura if. But I can't even get the selection onchange to trigger. 

 

Component is basically:

<aura:attribute name="rType" type="string"/>  
<lightning:select name="rType" label="Record Type" value="{!v.rType}" required="true" onchange="{!c.syncSelection}">

With controller:

syncSelection: function (component, event, helper) {
        console.log("this worked");

 

Best Answer chosen by Ryan Meyer
Naveen KNNaveen KN
I have tried to set options for the dropdown (hardcoded values) as you haven't shared the complete code. I am able to get the onchange alert
<aura:component implements="flexipage:availableForAllPageTypes" access="global">
    <aura:attribute name="rType" type="string" default="a,b"/>  
    <lightning:select name="rType" label="Record Type" value="{!v.rType}" required="true" onchange="{!c.syncSelection}">
        <option value="A" >A</option>
        <option value="A" >B</option>
    </lightning:select>
</aura:component>

controller code
syncSelection: function (component, event, helper) {
        alert("this worked");
    }

if you are still getting the issue, please share complete .cmp and controller code related to the dropdown

All Answers

Naveen KNNaveen KN
I have tried to set options for the dropdown (hardcoded values) as you haven't shared the complete code. I am able to get the onchange alert
<aura:component implements="flexipage:availableForAllPageTypes" access="global">
    <aura:attribute name="rType" type="string" default="a,b"/>  
    <lightning:select name="rType" label="Record Type" value="{!v.rType}" required="true" onchange="{!c.syncSelection}">
        <option value="A" >A</option>
        <option value="A" >B</option>
    </lightning:select>
</aura:component>

controller code
syncSelection: function (component, event, helper) {
        alert("this worked");
    }

if you are still getting the issue, please share complete .cmp and controller code related to the dropdown
This was selected as the best answer
mukesh guptamukesh gupta
Hi Ryan,

Please folllow below url for your solution approach:-

https://www.biswajeetsamal.com/blog/tag/lightningselect/

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh 


 
Ryan MeyerRyan Meyer

Thank you Naveen - it led me in the right direction, which was my additional line under syncselection that seemed to be causing the function to fail.

var activeSelect = event.getSource().get("v.value");