Application Event fired by a child component doesn't flow down other child component












4














I have 1 main component (Parent.cmp) which includes 2 components (Brother1.cmp and Brother2.cmp).



Brother1 fires an event which should cause an action in Brother2.



Documentation says that we should use APPLICATION events for that:




Application events follow a traditional publish-subscribe model. An application event is fired from an instance of a component. All components that provide a handler for the event are notified.




I've created an APPLICATION event and fire it from Brother1. According to the documentation, I expect the event to be distributed to Brother2. It is handled by Parent.cmp, but it never gets to Brother2.



What I tried:




  1. as the Parent.cmp receives the Brother1 event, I tried to fire a new Parent_evt APPLICATION event hoping it will be dispatched to Brother2. No success.

  2. The expression var brother1Event = $A.get("e.c:Brother1_evt"); doesn't work in my code, and even doesn't seem to be firing any event at all.


What am I missing ?



Thank you for your help.



Components code below:



TestEvents.app:



<aura:application extends="force:slds">
<c:Parent/>
</aura:application>


Parent.cmp



<aura:handler name="Brother1_evt" event="c:Brother1_evt" action="{!c.handleBrother1_evt}" />

<aura:attribute name="message" type="string" />
Parent message: <ui:outputtext value="{!v.message}" />

<div>
<c:Brother1/>
</div>

<div>
<c:Brother2/>
</div>




ParentController.js:



({
handleBrother1_evt : function(component, event, helper) {
component.set( "v.message", "Brother1 event Received");
}


})



Brother1.cmp



<aura:component >

<aura:registerEvent name="Brother1_evt" type="c:Brother1_evt" />

<aura:attribute name="message" type="string" />
<aura:handler name="Brother1_evt" event="c:Brother1_evt" action="{!c.handleBrother1_evt}" />

<lightning:button label="Click Me to fire an event from Brother 1!" variant="brand" onclick="{!c.handleBrother1Click}" />
<br/>
Brother 1 message: <ui:outputText value="{!v.message}" />




Brother1_evt.evt



<aura:event type="APPLICATION" description="Event template" />


Brother1Controller.js



({
handleBrother1Click : function(component, event, helper) {

var brother1Event = component.getEvent("Brother1_evt");
brother1Event.fire();
},

handleBrother1_evt : function(component, event, helper) {
component.set( "v.message", "Brother1 event Received");
}


Brother2.cmp



<aura:component >

<aura:handler name="Brother1_evt" event="c:Brother1_evt" action="{!c.handleBrother1_evt}" />

<aura:attribute name="message" type="string" />
Brother 2 message: <ui:outputText value="{!v.message}" />




Brother2Controller.js



({

handleBrother1_evt : function(component, event, helper) {
component.set( "v.message", "Brother1 event Received");
}


})



Output:



enter image description here










share|improve this question






















  • Can you try removing name attribute from the handler as the doc quotes 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.
    – codeyinthecloud
    6 hours ago








  • 1




    @codeyinthecloud That really should have been an answer. Also, it's exactly what I said.
    – sfdcfox
    6 hours ago
















4














I have 1 main component (Parent.cmp) which includes 2 components (Brother1.cmp and Brother2.cmp).



Brother1 fires an event which should cause an action in Brother2.



Documentation says that we should use APPLICATION events for that:




Application events follow a traditional publish-subscribe model. An application event is fired from an instance of a component. All components that provide a handler for the event are notified.




I've created an APPLICATION event and fire it from Brother1. According to the documentation, I expect the event to be distributed to Brother2. It is handled by Parent.cmp, but it never gets to Brother2.



What I tried:




  1. as the Parent.cmp receives the Brother1 event, I tried to fire a new Parent_evt APPLICATION event hoping it will be dispatched to Brother2. No success.

  2. The expression var brother1Event = $A.get("e.c:Brother1_evt"); doesn't work in my code, and even doesn't seem to be firing any event at all.


What am I missing ?



Thank you for your help.



Components code below:



TestEvents.app:



<aura:application extends="force:slds">
<c:Parent/>
</aura:application>


Parent.cmp



<aura:handler name="Brother1_evt" event="c:Brother1_evt" action="{!c.handleBrother1_evt}" />

<aura:attribute name="message" type="string" />
Parent message: <ui:outputtext value="{!v.message}" />

<div>
<c:Brother1/>
</div>

<div>
<c:Brother2/>
</div>




ParentController.js:



({
handleBrother1_evt : function(component, event, helper) {
component.set( "v.message", "Brother1 event Received");
}


})



Brother1.cmp



<aura:component >

<aura:registerEvent name="Brother1_evt" type="c:Brother1_evt" />

<aura:attribute name="message" type="string" />
<aura:handler name="Brother1_evt" event="c:Brother1_evt" action="{!c.handleBrother1_evt}" />

<lightning:button label="Click Me to fire an event from Brother 1!" variant="brand" onclick="{!c.handleBrother1Click}" />
<br/>
Brother 1 message: <ui:outputText value="{!v.message}" />




Brother1_evt.evt



<aura:event type="APPLICATION" description="Event template" />


Brother1Controller.js



({
handleBrother1Click : function(component, event, helper) {

var brother1Event = component.getEvent("Brother1_evt");
brother1Event.fire();
},

handleBrother1_evt : function(component, event, helper) {
component.set( "v.message", "Brother1 event Received");
}


Brother2.cmp



<aura:component >

<aura:handler name="Brother1_evt" event="c:Brother1_evt" action="{!c.handleBrother1_evt}" />

<aura:attribute name="message" type="string" />
Brother 2 message: <ui:outputText value="{!v.message}" />




Brother2Controller.js



({

handleBrother1_evt : function(component, event, helper) {
component.set( "v.message", "Brother1 event Received");
}


})



Output:



enter image description here










share|improve this question






















  • Can you try removing name attribute from the handler as the doc quotes 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.
    – codeyinthecloud
    6 hours ago








  • 1




    @codeyinthecloud That really should have been an answer. Also, it's exactly what I said.
    – sfdcfox
    6 hours ago














4












4








4







I have 1 main component (Parent.cmp) which includes 2 components (Brother1.cmp and Brother2.cmp).



Brother1 fires an event which should cause an action in Brother2.



Documentation says that we should use APPLICATION events for that:




Application events follow a traditional publish-subscribe model. An application event is fired from an instance of a component. All components that provide a handler for the event are notified.




I've created an APPLICATION event and fire it from Brother1. According to the documentation, I expect the event to be distributed to Brother2. It is handled by Parent.cmp, but it never gets to Brother2.



What I tried:




  1. as the Parent.cmp receives the Brother1 event, I tried to fire a new Parent_evt APPLICATION event hoping it will be dispatched to Brother2. No success.

  2. The expression var brother1Event = $A.get("e.c:Brother1_evt"); doesn't work in my code, and even doesn't seem to be firing any event at all.


What am I missing ?



Thank you for your help.



Components code below:



TestEvents.app:



<aura:application extends="force:slds">
<c:Parent/>
</aura:application>


Parent.cmp



<aura:handler name="Brother1_evt" event="c:Brother1_evt" action="{!c.handleBrother1_evt}" />

<aura:attribute name="message" type="string" />
Parent message: <ui:outputtext value="{!v.message}" />

<div>
<c:Brother1/>
</div>

<div>
<c:Brother2/>
</div>




ParentController.js:



({
handleBrother1_evt : function(component, event, helper) {
component.set( "v.message", "Brother1 event Received");
}


})



Brother1.cmp



<aura:component >

<aura:registerEvent name="Brother1_evt" type="c:Brother1_evt" />

<aura:attribute name="message" type="string" />
<aura:handler name="Brother1_evt" event="c:Brother1_evt" action="{!c.handleBrother1_evt}" />

<lightning:button label="Click Me to fire an event from Brother 1!" variant="brand" onclick="{!c.handleBrother1Click}" />
<br/>
Brother 1 message: <ui:outputText value="{!v.message}" />




Brother1_evt.evt



<aura:event type="APPLICATION" description="Event template" />


Brother1Controller.js



({
handleBrother1Click : function(component, event, helper) {

var brother1Event = component.getEvent("Brother1_evt");
brother1Event.fire();
},

handleBrother1_evt : function(component, event, helper) {
component.set( "v.message", "Brother1 event Received");
}


Brother2.cmp



<aura:component >

<aura:handler name="Brother1_evt" event="c:Brother1_evt" action="{!c.handleBrother1_evt}" />

<aura:attribute name="message" type="string" />
Brother 2 message: <ui:outputText value="{!v.message}" />




Brother2Controller.js



({

handleBrother1_evt : function(component, event, helper) {
component.set( "v.message", "Brother1 event Received");
}


})



Output:



enter image description here










share|improve this question













I have 1 main component (Parent.cmp) which includes 2 components (Brother1.cmp and Brother2.cmp).



Brother1 fires an event which should cause an action in Brother2.



Documentation says that we should use APPLICATION events for that:




Application events follow a traditional publish-subscribe model. An application event is fired from an instance of a component. All components that provide a handler for the event are notified.




I've created an APPLICATION event and fire it from Brother1. According to the documentation, I expect the event to be distributed to Brother2. It is handled by Parent.cmp, but it never gets to Brother2.



What I tried:




  1. as the Parent.cmp receives the Brother1 event, I tried to fire a new Parent_evt APPLICATION event hoping it will be dispatched to Brother2. No success.

  2. The expression var brother1Event = $A.get("e.c:Brother1_evt"); doesn't work in my code, and even doesn't seem to be firing any event at all.


What am I missing ?



Thank you for your help.



Components code below:



TestEvents.app:



<aura:application extends="force:slds">
<c:Parent/>
</aura:application>


Parent.cmp



<aura:handler name="Brother1_evt" event="c:Brother1_evt" action="{!c.handleBrother1_evt}" />

<aura:attribute name="message" type="string" />
Parent message: <ui:outputtext value="{!v.message}" />

<div>
<c:Brother1/>
</div>

<div>
<c:Brother2/>
</div>




ParentController.js:



({
handleBrother1_evt : function(component, event, helper) {
component.set( "v.message", "Brother1 event Received");
}


})



Brother1.cmp



<aura:component >

<aura:registerEvent name="Brother1_evt" type="c:Brother1_evt" />

<aura:attribute name="message" type="string" />
<aura:handler name="Brother1_evt" event="c:Brother1_evt" action="{!c.handleBrother1_evt}" />

<lightning:button label="Click Me to fire an event from Brother 1!" variant="brand" onclick="{!c.handleBrother1Click}" />
<br/>
Brother 1 message: <ui:outputText value="{!v.message}" />




Brother1_evt.evt



<aura:event type="APPLICATION" description="Event template" />


Brother1Controller.js



({
handleBrother1Click : function(component, event, helper) {

var brother1Event = component.getEvent("Brother1_evt");
brother1Event.fire();
},

handleBrother1_evt : function(component, event, helper) {
component.set( "v.message", "Brother1 event Received");
}


Brother2.cmp



<aura:component >

<aura:handler name="Brother1_evt" event="c:Brother1_evt" action="{!c.handleBrother1_evt}" />

<aura:attribute name="message" type="string" />
Brother 2 message: <ui:outputText value="{!v.message}" />




Brother2Controller.js



({

handleBrother1_evt : function(component, event, helper) {
component.set( "v.message", "Brother1 event Received");
}


})



Output:



enter image description here







lightning-aura-components lightning-events






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 6 hours ago









fredbe

354




354












  • Can you try removing name attribute from the handler as the doc quotes 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.
    – codeyinthecloud
    6 hours ago








  • 1




    @codeyinthecloud That really should have been an answer. Also, it's exactly what I said.
    – sfdcfox
    6 hours ago


















  • Can you try removing name attribute from the handler as the doc quotes 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.
    – codeyinthecloud
    6 hours ago








  • 1




    @codeyinthecloud That really should have been an answer. Also, it's exactly what I said.
    – sfdcfox
    6 hours ago
















Can you try removing name attribute from the handler as the doc quotes 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.
– codeyinthecloud
6 hours ago






Can you try removing name attribute from the handler as the doc quotes 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.
– codeyinthecloud
6 hours ago






1




1




@codeyinthecloud That really should have been an answer. Also, it's exactly what I said.
– sfdcfox
6 hours ago




@codeyinthecloud That really should have been an answer. Also, it's exactly what I said.
– sfdcfox
6 hours ago










1 Answer
1






active

oldest

votes


















4














As 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.




You need to remove the "name" attribute.






share|improve this answer

















  • 2




    +1 You beat me by seconds!
    – codeyinthecloud
    6 hours ago











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "459"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f244676%2fapplication-event-fired-by-a-child-component-doesnt-flow-down-other-child-compo%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









4














As 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.




You need to remove the "name" attribute.






share|improve this answer

















  • 2




    +1 You beat me by seconds!
    – codeyinthecloud
    6 hours ago
















4














As 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.




You need to remove the "name" attribute.






share|improve this answer

















  • 2




    +1 You beat me by seconds!
    – codeyinthecloud
    6 hours ago














4












4








4






As 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.




You need to remove the "name" attribute.






share|improve this answer












As 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.




You need to remove the "name" attribute.







share|improve this answer












share|improve this answer



share|improve this answer










answered 6 hours ago









sfdcfox

246k11186423




246k11186423








  • 2




    +1 You beat me by seconds!
    – codeyinthecloud
    6 hours ago














  • 2




    +1 You beat me by seconds!
    – codeyinthecloud
    6 hours ago








2




2




+1 You beat me by seconds!
– codeyinthecloud
6 hours ago




+1 You beat me by seconds!
– codeyinthecloud
6 hours ago


















draft saved

draft discarded




















































Thanks for contributing an answer to Salesforce Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f244676%2fapplication-event-fired-by-a-child-component-doesnt-flow-down-other-child-compo%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Trompette piccolo

Slow SSRS Report in dynamic grouping and multiple parameters

Simon Yates (cyclisme)