0

i am getting the following error.

Uncaught Action failed: c:qf_Questionbuilder$controller$SelectLookupItem [Cannot read property 'config' of undefined]

This is when my helper tries to refresh the list.

in summary i have a list that i iterate though, on one of the list items if its called it passes the list to a controller, the controller makes a change and then passes the recordset back.

when it runs the component.set("v.PageQuestions", actionResult.getReturnValue());

line it errors.

i have created a send list and made it the same as the first, if i update that then there is no error. that leads me to summise that i am trying to update a list that is locked or some such.

the interesting thing is that when the error appears on the screen the list is rendered with the data changed behind the error window, so it is refreshing the dataset then why trying to re-render it failing ?

any advice greatly appreciated

summary code below - apologies if its not easy to read or too long !

.cmp

<aura:component controller="qf_questionBuilder" 
                implements="forceCommunity:availableForAllPageTypes,force:apphostable,force:hasRecordId,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:lightningQuickActionWithoutHeader" 
                access="global">


    <aura:handler name="init" value="{!this}" action="{!c.setUpScreen}" />

    <aura:attribute name="PageQuestions" type="qf_Answers[]" />

-- please note that the qf_answers is a class that i have created - originally i just had it set as list.

public class qf_Answers {

    @auraenabled
    public id AnswerID {get;Set;}    
    @auraenabled
    public string QuestionText {get;set;}
    @auraenabled
    public string QuestionHelpText {get;Set;}
    @auraenabled
    public decimal QuestionMinValue {get;Set;}
    @auraenabled
    public decimal QuestionMaxValue {get;set;}
    @auraenabled
    public boolean QuestionRequired {get;Set;}
    @auraenabled
    public string QuestionType {get;set;}
    @auraEnabled
    public object AnswerValue {get;set;}
    @auraEnabled
    public string AnswerStreet {get;set;}
    @auraEnabled
    public string AnswerCity {get;set;}
    @auraEnabled
    public string AnswerProvince {get;set;}
    @auraEnabled
    public string AnswerPostalCode {get;set;}
    @auraEnabled
    public string AdditionalNotes {get;set;}
    @auraEnabled
    public string AnswerLookupID {get;set;}
}

the relevant part of cmp ....

 <!-- Show the Questions -->
            <section class="slds-card slds-p-around_medium">
                <div class="slds-form"> 
                    <aura:iteration items="{!v.PageQuestions}" var="PQs" indexVar="PQsIndex">
               <aura:renderIf isTrue="{!PQs.QuestionType == 'Lookup'}">
                                            <!--IF NO VALUE PRESENT-->

                                            <aura:If isTrue="{!PQs.AnswerValue == NULL}">
                                                <div  class="slds-combobox_container">
                                                    <div class="slds-combobox slds-dropdown-trigger slds-dropdown-trigger_click slds-is-open" aria-expanded="true" aria-haspopup="listbox" role="combobox">
                                                            <lightning:input id="{!PQs.AnswerID}"
                                                                             type="search"
                                                                             placeholder="Search..."
                                                                             variant="label-hidden" 
                                                                             value="{!v.Lookup}"
                                                                             onchange="{!c.LookupChanged}"
                                                                             messageWhenBadInput=""
                                                                             required="{!PQs.QuestionRequired}" 
                                                                             aria-controls="{!PQs.AnswerID + '-listbox-searchresults'}"/>                                                        
                                                        <!-- renders list on value entered into searchstring -->
                                                        <aura:renderIf isTrue="{!not(empty(v.Lookup))}">
                                                            <div id="{!PQs.AnswerID + '-listbox-searchresults'}" class="slds-dropdown slds-dropdown_length-with-icon-7 slds-dropdown_fluid" role="listbox">
                                                                <ul class="slds-listbox slds-listbox_vertical" role="presentation">
                                                                    <aura:iteration items="{!v.LookupResults}" var="Lkup" indexVar="LkupIndex">
                                                                        <!---List Items onclick="{!c.SelectLookupItem}" sets {!PQs.AnswerValue} -->
                                                                        <li role="presentation" 
                                                                            class="slds-listbox__item"
                                                                            onclick="{!c.SelectLookupItem}"
                                                                            data-value="{!Lkup.DisplayValue}"
                                                                            data-PQsId="{!PQs.AnswerID}"> 
                                                                            <div class="slds-media slds-listbox__option slds-listbox__option_entity" role="option">
                                                                                <span class="slds-media__body">
                                                                                    <span class="slds-listbox__option-text slds-listbox__option-text_entity">
                                                                                        <span>
                                                                                            {!Lkup.DisplayValue} 
                                                                                        </span>
                                                                                    </span>
                                                                                </span>
                                                                            </div>
                                                                        </li>
                                                                    </aura:iteration>
                                                                </ul>
                                                            </div>
                                                        </aura:renderIf>
                                                    </div>
                                                </div>
                                                <!--IF VALUE IS PRESENT-->
                                                <aura:set attribute="else">
                                                    <div class="slds-combobox_container slds-has-selection">
                                                        <div class="slds-combobox slds-dropdown-trigger slds-dropdown-trigger_click" aria-expanded="false" aria-haspopup="listbox" role="combobox">
                                                            <div class="slds-combobox__form-element slds-input-has-icon slds-input-has-icon_left-right" role="none">
                                                                <input type="text" class="slds-input slds-combobox__input slds-combobox__input-value" autoComplete="off" role="textbox" readonly="" value="{!PQs.AnswerValue}" />
                                                                <button class="slds-button slds-button_icon slds-input__icon slds-icon_x-small slds-input__icon_right" onclick="{!c.ClearLookup}" title="Remove attached">
                                                                    <lightning:icon class="slds-icon slds-icon_x-small" iconName="utility:close" size="x-small" alternativeText="Close" />
                                                                </button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </aura:set>
                                            </aura:If>


                                        </aura:renderIf>

so this produces a dynamic picklist - which works, when they choose an option it should set the item to be the value selected and then reload the page

the java for this

SelectLookupItem : function(component, event, helper){
            var clickIndex = event.currentTarget.dataset.PQsId;
            confirm(clickIndex);
            var clickValue = event.currentTarget.dataset.value;
            var CurrentAnswers = component.get('v.PageQuestions');
            helper.refreshAnswers(11, clickValue, component, event);
            component.set('v.Lookup','');

        },

here is the helper

refreshAnswers : function(QuestionID, clickValue, component, event){     
        var action = component.get("c.refreshData");
        var theQuestionset =  component.get("v.PageQuestions");

        action.setParams({"UpdateIndex" : QuestionID,"UpdateValue" : clickValue, "currentAnswers" : theQuestionset});

        //Set up the callback

        var self = this;

        action.setCallback(this, function(actionResult) {
            var state = actionResult.getState();
            if (component.isValid() && state === "SUCCESS") {
                component.set("v.PageQuestions", actionResult.getReturnValue());
            }            
        });
        $A.enqueueAction(action);

    }

and finally the apex

@auraenabled
    public static list <qf_Answers> refreshData (integer UpdateIndex, string UpdateID, string LookupID, string UpdateValue, list <qf_Answers> currentAnswers){

        system.debug('Refreshdata Started' + currentAnswers);
        list <qf_Answers> NewAnswers = currentAnswers ;

        integer x=0 ;
        for (qf_Answers UpdateAnswer : NewAnswers){
            if ( x == UpdateIndex ){

                updateAnswer.AnswerValue = UpdateValue ;
                break;
            }
            x ++;
        }
        system.debug('Refreshdata Completed' + NewAnswers);

        return NewAnswers ;

    }

Ok so removing this code, means the data refreshes and the record is updated. so it must be in this rendering that the issue is

 <!--LOOKUP-->
                                        <aura:renderIf isTrue="{!PQs.QuestionType == 'Lookup'}">
                                            <!--IF NO VALUE PRESENT-->

                                            <aura:If isTrue="{!PQs.AnswerValue == NULL}">
                                                <div  class="slds-combobox_container">
                                                    <div class="slds-combobox slds-dropdown-trigger slds-dropdown-trigger_click slds-is-open" aria-expanded="true" aria-haspopup="listbox" role="combobox">
                                                            <lightning:input id="{!PQs.AnswerID}"
                                                                             type="search"
                                                                             placeholder="Search..."
                                                                             variant="label-hidden" 
                                                                             value="{!v.Lookup}"
                                                                             onchange="{!c.LookupChanged}"
                                                                             messageWhenBadInput=""
                                                                             required="{!PQs.QuestionRequired}" 
                                                                             aria-controls="{!PQs.AnswerID + '-listbox-searchresults'}"/>                                                        
                                                        <!-- renders list on value entered into searchstring -->
                                                        <aura:renderIf isTrue="{!not(empty(v.Lookup))}">
                                                            <div id="{!PQs.AnswerID + '-listbox-searchresults'}" class="slds-dropdown slds-dropdown_length-with-icon-7 slds-dropdown_fluid" role="listbox">
                                                                <ul class="slds-listbox slds-listbox_vertical" role="presentation">
                                                                    <aura:iteration items="{!v.LookupResults}" var="Lkup" indexVar="LkupIndex">
                                                                        <!---List Items onclick="{!c.SelectLookupItem}" sets {!PQs.AnswerValue} -->
                                                                        <li role="presentation" 
                                                                            class="slds-listbox__item"
                                                                            onclick="{!c.SelectLookupItem}"
                                                                            data-value="{!Lkup.DisplayValue}"
                                                                            data-PQsId="{!PQs.AnswerID}"> 
                                                                            <div class="slds-media slds-listbox__option slds-listbox__option_entity" role="option">
                                                                                <span class="slds-media__body">
                                                                                    <span class="slds-listbox__option-text slds-listbox__option-text_entity">
                                                                                        <span>
                                                                                            {!Lkup.DisplayValue} 
                                                                                        </span>
                                                                                    </span>
                                                                                </span>
                                                                            </div>
                                                                        </li>
                                                                    </aura:iteration>
                                                                </ul>
                                                            </div>
                                                        </aura:renderIf>
                                                    </div>
                                                </div>
                                                <!--IF VALUE IS PRESENT-->
                                                <aura:set attribute="else">
                                                    <div class="slds-combobox_container slds-has-selection">
                                                        <div class="slds-combobox slds-dropdown-trigger slds-dropdown-trigger_click" aria-expanded="false" aria-haspopup="listbox" role="combobox">
                                                            <div class="slds-combobox__form-element slds-input-has-icon slds-input-has-icon_left-right" role="none">
                                                                <input type="text" class="slds-input slds-combobox__input slds-combobox__input-value" autoComplete="off" role="textbox" readonly="" value="{!PQs.AnswerValue}" />
                                                                <button class="slds-button slds-button_icon slds-input__icon slds-icon_x-small slds-input__icon_right" onclick="{!c.ClearLookup}" title="Remove attached">
                                                                    <lightning:icon class="slds-icon slds-icon_x-small" iconName="utility:close" size="x-small" alternativeText="Close" />
                                                                </button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </aura:set>
                                            </aura:If>


                                        </aura:renderIf>
  • did you check what is the return value of actionResult.getReturnValue() before error throws? – sdandamud1 Feb 20 at 16:10
  • @ sdandamud1 - thanks for coming back to me it is sucessfull and when i post it to another list there is no error. it only errors when i post it back to the v.PageQuestions, which i assume is because its in the iteration ? the array passed and returned is exactly the same format – Phil Macleod Feb 20 at 16:13
  • when i do a confirm on it i get . [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object] .. so i know its getting the right records back, when i iterate through them there are no issues – Phil Macleod Feb 20 at 16:17
  • for testing purposes i created v,pagequestions2 i then changes the line component.set("v.PageQuestions", actionResult.getReturnValue()); to be component.set("v.PageQuestions2", actionResult.getReturnValue()); it does this without error, so my next step was to assign pagequestions2 to pagequestions - this threw an error – Phil Macleod Feb 20 at 16:24
  • let's go through based on error message. r u using any where config ? – sdandamud1 Feb 20 at 16:39
0

i observed your code used aura:renderIf i am Not sure if this would apply in your scenario in iteration , but have you tried using aura:if instead of aura:renderIf? because library doc. it's

Deprecated. Use aura:if instead. This component allows you to conditionally render its contents. It renders its body only if isTrue evaluates to true. The else attribute allows you to render an alternative when isTrue evaluates to false.

|improve this answer|||||
  • thanks - i noted that depreciation as well, and have changed the code to test but it has not resolved this issue. however Appreciate the tip. – Phil Macleod Feb 20 at 16:26
0

thanks for the help and advice i got to the bottom of it,

in summary we were using the wrong aria control !!

 aria-controls="{!PQs.AnswerID + '-listbox-searchresults'}"

should be

ariaControls="{!PQs.AnswerID + 'LkupRslt'}"/>

the whole piece looks like this

<lightning:input id="{!PQs.AnswerID}"
                                                                             type="text"
                                                                             placeholder="Search..."
                                                                             variant="label-hidden"
                                                                             value="{!v.Lookup}"
                                                                             onchange="{!c.LookupChanged}"
                                                                             messageWhenBadInput=""
                                                                             required="{!PQs.QuestionRequired}"
                                                                             ariaControls="{!PQs.AnswerID + 'LkupRslt'}"/>
|improve this answer|||||

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.