Winter 17 release : event.getSource is not a function on lightning:button

event.getSource() is a proprietary API only available on Aura Events, so, no, you can't use that with lightning:button, just like all components from the lightning namespace, they will not rely on the Aura Proprietary Event System, instead they rely on the DOM Events, using the native event when possible or a custom DOM event, just like a regular <button> will do.

Getting the label of the lightning:button is probably not a good option here, considering that the label might change overtime (maybe even translated), instead you can set the name and/or value on the lightning:button, and use that to identify which button was clicked.

Anyhow, this is an example:

<lightning:button variant="brand" label="Submit" name="save" value="something" onclick="{!c.save}" />

Then in your controller:

({
    save: function (cmp, event) {
        alert(event.currentTarget.name);
        alert(event.currentTarget.value);
    }
})

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.


I notice in Which Button Was Pressed? that they use the press rather than onclick attribute. They also use a ui:button rather than a lightning:button.

With ui:button press is defined as an event. With lightning:button onclick is just an attribute.

To me this suggests that when you click the ui:button there is extra JavaScript building up the event model and populating the extra arguments to the controller method.

In contrast, lightning:button might be directly calling the controller method like any standard client site button.

Looking at the rendered HTML source would likely give you more clues. I could be way off here and it isn't clear why the Base Lightning Component isn't built on top of the ui component with the same press event.