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:

Sindhuja Ravi said...

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

Nbits said...

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

Unknown said...

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

Dharani M said...

Nice information
salesforce training in Marathahalli

salesforce admin training in Marathahalli

salesforce developer training in Marathahalli

asha said...

Nice Post.... Keep on sharing this post
salesforce training in Bangalore

salesforce admin training in Bangalore

salesforce developer training in Bangalore

trustno1 said...

html css examples
Noframes tag noframes element

Unknown said...

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

Salesforce Developer said...

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

kirankumar said...

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 ­

Amit Kumar Singh said...


i am a freelancer and work according to contract, for more details contact us with the information provided below.
play game and win snapdeal lucky draw coupon 2019. contact us, play and win snapdeal lucky draw winner prizes.
lucky draw snapdeal contact number 6289379055 call to get more information
Lucky Draw Snapdeal costomer care number
snapdeal lucky draw contact number
snapdeal lucky draw contest 2019
snapdeal lucky draw 2019 list
snapdeal lucky draw contact number
snapdeal lucky draw 2019

Best Regards
snapdeal lucky draw winners 2019

Johan said...

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

Johan said...

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

Mohit Bansal said...

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.

Manuvel said...

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

Emily said...

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

Elvis said...

Thank you writers team for the wonderful article. Adnoc ICV Certification Agencies

blackthundar said...

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

Post a Comment

 
| ,