Application Event fired by a child component doesn't flow down other child component
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:
- 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.
- 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:
lightning-aura-components lightning-events
add a comment |
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:
- 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.
- 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:
lightning-aura-components lightning-events
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
add a comment |
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:
- 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.
- 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:
lightning-aura-components lightning-events
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:
- 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.
- 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:
lightning-aura-components lightning-events
lightning-aura-components lightning-events
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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.
2
+1 You beat me by seconds!
– codeyinthecloud
6 hours ago
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
2
+1 You beat me by seconds!
– codeyinthecloud
6 hours ago
add a comment |
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.
2
+1 You beat me by seconds!
– codeyinthecloud
6 hours ago
add a comment |
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.
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.
answered 6 hours ago
sfdcfox
246k11186423
246k11186423
2
+1 You beat me by seconds!
– codeyinthecloud
6 hours ago
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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