How To Find Button Click Using Lightning Component

Requirement:

On LC there are two buttons. Both buttons have same function how to get which button have clicked.

Solution
Create a component ButtonClick.cmp

<!--c:ButtonClicked->
<aura:component >
    <aura:attribute name="whichButton" type="String" />
    
    <p>You clicked: {!v.whichButton}</p>

    <ui:button aura:id="button1" label="Click me" press="{!c.pressMe}"/>
    <ui:button aura:id="button2" label="Click me too" press="{!c.pressMe}"/>

</aura:component>


/* ButtonClickedController.js */
({
    pressMe: function(cmp, event, helper) {
        var whichOne = event.getSource().getLocalId();
        console.log(whichOne);
        cmp.set("v.whichButton", whichOne);
    }

})



Create a app Test.app for Testing

<aura:application extends="force:slds">
   
     <c:ButtonClicked/>
<!-- here c: is org. namespace prefix-->

</aura:application>



Comments

Popular posts from this blog

Salesforce Spring 16 Release Exam (Maintenance Exam Q&A) for Developer 201 Admin

Show Hyper Link On Add Error in Salesforce Trigger

Show the Success Message before Redirecting the Detail page on Visualforce Page