1

When I have a button inside a component inside a lightning:card either as a body element or an action, the onClick is never fired. If I move the lightning:button outside of the container, the event fires as expected. I've tried searching everywhere for how to handle this situation as I'm sure it's a scoping issue, but I can't find a solid answer.

Here's an example component:

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
    <lightning:card title="Program Enrollment" iconName="standard:marketing_actions">
        <aura:set attribute="actions">
            <lightning:button label="Request" onclick="{!v.requestHelp}" />
        </aura:set>
        <div class="slds-align_absolute-center" style="height: 5rem;">
            Nothing here to see!
        </div>
    </lightning:card>
</aura:component>
({
    requestHelp : function() {
        alert("hello");
    }
})
  • 1
    it will be onclick={!c.requestHelp} not 'v.requestHelp' – Kushal Chauhan Nov 17 at 19:11
2

It should be c.requestHelp not v.requestHelp

c. is used to call controller functions and v. is used to access attribute values

  • doh! thank you! – Benny Nov 17 at 19:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.