I’m trying to get the label of the button the user has clicked on by using event.getSource, but I’m getting the error that event.getSource is not a function.
Component
<lightning:button variant="brand" label="Submit" onclick="{!c.save}" />
Controller
save: function(component, event, helper){ var target = event.getSource(); console.log(target.get("v.label")); }
Error
Uncaught Action failed: c$TimeTrackingTab$controller$save [event.getSource is not a function]
I found this function documented by Salesforce here.
Any ideas?
Answer
You’ll have an official answer in Spring 17, event.getSource()
will be the way to go as you were expecting.
You can find more in the release notes here.
Attribution
Source : Link , Question Author : joshuadelange , Answer Author : Fabien Taillon