I'm building/modifying a tool using lightning components which houses (dynamically-created) input components in a larger wrapper component. Currently, the inputs correctly send events to the wrapper (to update a master map of values), but because some inputs are linked in different ways, I then need to send an event (linkEvent) from the wrapper to reach and update other inputs.
EDIT: I should mention, there are multiple nested 'levels' between the Wrapper and these Inputs, and some Inputs themselves contain sub-inputs which need to communicate in the same way.
Here's some code to illustrate the issue:
WrapperComp:
<aura:registerEvent name="linkEvent" type="c:MyLinkEvent" />
//
buildComponent:function(component, options) {
$A.createComponent('InputComp', options, function(el) {
var body = component.get('v.body');
if (options['link']) {
el.addEventHandler('linkEvent', el.getReference('c.handler'));
}
body.push(el);
component.set('v.body', body);
});
},
handleComponentEvent:function(component, event, helper) {
var val = event.getParam('payload');
var link = event.getParam('link');
// Do some things
var ev = component.getEvent('linkEvent');
ev.setParams({'payload':val,'link':link});
ev.fire();
}
InputComp:
<aura:registerEvent name="linkEvent" type="c:MyLinkEvent" />
//
handler:function(component, event) {
console.log('This is not being logged');
var eLink = event.getParam('link');
var cLink = component.get('v.link');
if (eLink==cLink) {
// Do some things
}
}
My inputs are reaching the wrapper without a problem, I just need to send information back to children after. My two main questions are: Can this be accomplished with Component events? And if so, do I need to register the event in the parent (because that's where I call addEventHandler()
), or in the child? Or both?