Tuesday, February 7, 2017

How to know which button was pressed in lightning component?

How to know which button was pressed in lightning component?


To find out which button was pressed in a component containing multiple buttons, use Component.getLocalId().

Let’s look at a component that contains multiple buttons. Each button has a unique local ID, set by an aura:id attribute.

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

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


Use event.getSource() in the client-side controller to get the button component that was clicked. Call getLocalId() to get the aura:id of the clicked button.

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


Example Component: 



Controller.Js  : Highlighted code



out put:





for reference : 

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_cb_which_button_pressed.htm


17 comments:

  1. Thank you for taking the time to provide us with your valuable information. We strive to provide our candidates with excellent care and we take your comments to heart.As always, we appreciate your confidence and trust in us
    SEO Company in India

    ReplyDelete
  2. thank you for sharing such a good and useful information, please keep on share like this
    salesforce training in hyderabad
    salesforce online training

    ReplyDelete
  3. Thanks for sharing this Informative content. Well explained. Got to learn new things from your Blog salesforce online classes

    ReplyDelete
  4. Poker sendiri merupakan permainan yang sedikit sulit di menangkan karena permainan ini tidak tergantung pada jenis kartu yang anda dapatkan melainkan cara dan teknik anda bermain
    asikqq
    http://dewaqqq.club/
    http://sumoqq.today/
    interqq
    pionpoker
    bandar ceme
    freebet tanpa deposit
    paito warna terlengkap
    syair sgp

    ReplyDelete
  5. Nice article! I found many useful information in your blog, it was awesome to read,thanks for sharing this great content, keep sharing....
    Salesforce Consulting Services

    ReplyDelete
  6. Great information and useful
    Sanjary Academy is the best Piping Design institute in Hyderabad, Telangana. It is the best Piping design Course in India and we have offer professional Engineering Courses like Piping design Course, QA/QC Course, document controller course, Pressure Vessel Design Course, Welding Inspector Course, Quality Management Course and Safety Officer Course.
    Piping Design Course in Hyderabad ­

    ReplyDelete
  7. I must appreciate you for providing such a valuable content for us. This is one amazing piece of article. Helped a lot in increasing my knowledge.salesforce admin training in bangalore

    ReplyDelete
  8. Really a awesome blog for the freshers. Thanks for posting the information.salesforce developer training in bangalore

    ReplyDelete
  9. Quick! Book Your Spot for Wednesday[25th March, 11 AM(IST) | 4 PM(GST) | 11:00 AM(PDT)] WEBINAR on topic: Bulk Export Operations in Salesforce using BOFC App
    You'll learn
    How to Export Multiple Page-Layouts & Fields Presence Matrix, Export Multiple Objects & Rules, Process Builders & Flows, etc.

    ReplyDelete
  10. Thanks for sharing this article. very useful and effective article. please check our website for all new article. Audit Firms in UAE

    ReplyDelete
  11. Very useful information. please keep sharing article like this. also you can visit our website for all new article. Bookkeeping Services in Dubai

    ReplyDelete
  12. Reading gives more energy. Thanks for this wonderful article. Chartered accountants in Dubai

    ReplyDelete