I am creating dynamic checkbox component in Lightning in helper class but I am not able to capture click event in controller class as value is undefined for event.
Helper
var checkBoxDef = [];
var checkBoxCmps = [];
checkBoxDef.push([
"ui:inputCheckbox",
{
"class" : "design-checkbox",
"id" : "accordion-c-"+i,
"aura:id" : "accordion-c-"+i,
"click": component.getReference("c.handlePress")
}
]);
$A.createComponents(
checkBoxDef,
function(cmps, status, errorMessage){
if (status === "SUCCESS") {
for (var i = 0; i < cmps.length; i++) {
var checkBoxCmp = cmps[i];
checkBoxCmps.push(checkBoxCmp);
}
}
else if (status === "INCOMPLETE") {
console.log("No response from server or client is offline.")
}
else if (status === "ERROR") {
console.log("Error: " + errorMessage);
}
}
);
Controller
handlePress : function(component) {
var sectionId;
console.log(component);
if (event.target != undefined) {
sectionId = event.target.id;
} else {
sectionId = event.getSource().getLocalId();
}
}
Error
This page has an error. You might just need to refresh it. Action failed: c:CCustomLightningPage$controller$handlePress [Cannot read property 'target' of undefined] Failing descriptor: {c:CCustomLightningPage$controller$handlePress}
event
parameter change and see a new issue, please open a new question with the full repro (.cmp, helper, controller file) and the new error or what things you have tried and what is not working as you'd expect. – TrevorBliss Apr 20 '17 at 17:14