I am trying to create a lightning:inputField using $A.createComponents. The issue I have is that I am not able to add an onchange event. The field Level__c is a picklist field.
When I use the following code in the component the onchange event works fine:
<lightning:inputField fieldName="Level__c" onchange="{!c.reload}"/>
However, when I use the following code within $A.createComponents I get an error message ,Cannot read property 'indexOf' of undefined'.
Component
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<aura:attribute name="contract" type="Contract__c" default="{ 'sobjectType': 'Contract__c' }" access="public"/>
<aura:handler name="init" value="{!this}" action="{!c.init}" />
<lightning:recordEditForm recordId="{!v.recordId}" objectApiName="Contract__c">
{!v.body}
</lightning:recordEditForm>
Controller
({
init: function(cmp, event, helper){
helper.createComponents(cmp);
},
reload: function(cmp, event, helper){
helper.createComponents(cmp);
}})
Helper
({
createComponents: function(cmp){
console.log(cmp.getReference("c.reload"));
$A.createComponent("lightning:inputField", {"fieldName" : "Level__c", "aura:id": "Level__c", "onchange":cmp.getReference("c.reload")},
function(newCmp, status, errorMessage){
if (status === "SUCCESS") {
var body = cmp.get("v.body");
body.push(newCmp);
cmp.set("v.body", body);
}
else if (status === "INCOMPLETE") {
console.log("No response from server or client is offline.")
}
else if (status === "ERROR") {
console.log("Error: " + errorMessage);
}
});
},})