2

Lightning Event:

tripEventer, attribute - trip, Trip__c

Component Item:

<aura:registerEvent name="openTripEvent" type="c:tripEventer"/>
<lightning:button class="slds-align_absolute-center" onclick="{!c.openTripAction}" label="Open Form"/><br/>

Component Item Controller:

openTripAction: function (component, event, helper) {
var action = component.getEvent('openTripEvent');
action.setParam('trip', component.get("v.trip"));
action.fire();
alert('gree from item button');
}

Component Form:

<aura:attribute type="String" name="test" default="nothing"/>
<aura:handler name="openTripEvent" action="{!c.handleOpenForm}" event="c:tripEventer"/>

Component Form Controller:

handleOpenForm: function (component, event, helper) {
component.set("v.test", "something");
alert('im here');
}

and I don't see alert 'i'm here, handleOpenForm js-action isn't fired

1 Answer 1

2

Do not specify the name attribute on an aura:handler for application events. This is specifically stated in the documentation:

The handler for an application event won’t work if you set the name attribute in <aura:handler>. Use the name attribute only when you’re handling component events.

Removing the name attribute should resolve the problem.

3
  • 1
    but it's component event.i thought about it. so you think that [item component] inside of [list component] can't catch [form component]? just change to application event?
    – Ivan S.
    Commented Jun 6, 2019 at 14:53
  • Hey, Ivan, did this solve the issue for you? Hi @sfdcfox, I have a managed package to work with and I try to handle a component event (fired in the same way as in the example above - component.getEvent('openTripEvent')). And it couldn't get handled by the wrapping parent (another custom Aura component). Commented Mar 28 at 9:48
  • ah, as the managed event is declared as type="APPLICATION" I had to add the name in my case to be able to handle it. thanks sfdcofx, was helpful to see the correct way to implement the component events. Commented Mar 28 at 10:04

You must log in to answer this question.

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