1

Why does <ui:button> work but <lightning:button> does not work?

Component:

<aura:component>
    <ltng:require 
        styles="{!$Resource.SLDS212 + '/assets/styles/lightning-design-system-ltng.css'}"
        scripts="{!$Resource.jsLibraries + '/jsLibOne.js'}"
        afterScriptsLoaded="{!c.scriptsLoaded}" />
    <ui:button label="myButton" press="{!c.doSomething}"/>
    <lightning:button name="myButton" onclick="{!c.doSome}"/>
</aura:component>

Controller:

({
    doSomething: function(cmp, event, helper) {
        var button = event.getSource().get("v.label");
        alert(button);

    },
    doSome: function(cmp, event, helper) {
        var button = event.getSource().get("v.name");
        alert(button);

    }
})
0

1 Answer 1

2

The name attribute is optional, use label

<lightning:button label="Submit" onclick="{! c.doSome }" />

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

You may get an error on getSource() if you are on winter box, there seems to be a fix in Spring 17:

Lockerservice and event.getSource()

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

2
  • Yeah, that tripped me up, too. Silly Lightning.
    – sfdcfox
    Commented Jan 31, 2017 at 1:04
  • 1
    One more thing : You may get an error on getSource() if you are on winter box, there seems to be a fix in Spring 17 salesforce.stackexchange.com/questions/155040/…
    – Rao
    Commented Jan 31, 2017 at 1:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .