10

I have a lightning component that is using ui:inputSelect.

The component code:

            <div class="slds-form-element__control">
                <ui:inputSelect class="slds-select" aura:id="quals" change="{!c.getPreCodes}">
                    <aura:iteration items="{!v.questions}" var="q">
                         <ui:inputSelectOption aura:id="question" text="{!q.Id}" label="{!q.Question_Text__c}"/>
                    </aura:iteration>
                </ui:inputSelect>
            </div>

The controller:

    getPreCodes : function(cmp, event, helper){
        var selected = cmp.find("quals").get("v.value");

        var action = cmp.get("c.getPreCodes");
        action.setParams({
            "qualID" : selected
        });
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {

                console.log('precodes: ', response.getReturnValue());

            }
        });

        $A.enqueueAction(action);
    }

The basic logic is that the uiSelect is dynamically populated on init (this works fine). When a user makes a selection the "change" parameter function is fired to retrieve a list from the database and pass it to another component.

However, the change function {!c.getPreCodes} seems to be called recursively causing a

"Something has gone wrong. AuraClientService.postProcess: error in processing [RangeError: Maximum call stack size exceeded] . Please try again."

error. If I comment out the enqueueAction the function only runs once (nothing is called recursively) so I suspect it has something to do with the controller call.

17

As per the doc, it is recommended to use different names for the client side and server side methods/actions.

Use unique names for client-side and server-side actions in a component. A JavaScript function (client-side action) with the same name as a server-side action (Apex method) can lead to hard-to-debug issues.

So all you need to do is, change your client-side controller's method getPreCodes to something like getPreCodeData

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.