Lightning component error handleOnBlur event

I have an iteration on a component with an ui:inputNumber inside, which has an onchange event that calls a server side action. If after i change the value, i click on an input after the onchange is complete it throws me an error:

Uncaught Action failed: ui:inputSmartNumber$controller$handleOnBlur
[Cannot read property ‘indexOf’ of undefined]

I have also tried this with the blur event but the error still persists.

Some code for a preview:

Component:

<aura:component controller="c_MyController" implements="force:lightningQuickActionWithoutHeader,flexipage:availableForAllPageTypes,force:hasRecordId" access="global">
    <aura:attribute name="array" type="Object[]"/>
    <aura:iteration items="{!v.array}" var="obj">
         <ui:inputNumber value="{!obj.Number}" change="{!c.callAction}"/>
    </aura:iteration>
</aura:component>

Controller:

callAction : function(component, event, helper) {
    var action = component.get("c.myAction");

    action.setCallback(this,function(response){
        var state = response.getState();
        if(state === 'SUCCESS'){
            component.set("v.array", response.getReturnValue());
        }else if (state === "ERROR") {
            console.log(response.getError());
        }
    });
    $A.enqueueAction(action);
},

Server Side Controller:

 @AuraEnabled
public static List<MyObject__c> myAction(){
    return [Select Id From MyObject__c];
}

Edit: I believe that this is happening because of this line : component.set("v.array", response.getReturnValue()); although it shouldn’t. I believe the problem is that the focused element while the onchange event is running is rebuilt. But i have no idea how to workaround this issue.

Answer

Attribution
Source : Link , Question Author : Marco Galvão , Answer Author : Community

Leave a Comment