0

I have custom Lightning component form but i get a javascript error on console, i suppose something i am doing wrong.

<!--@ggalaios 20/11/19: ea_RelationshipWithea -->
    <aura:attribute name="RelationshipWithea_Options" type="List" default="[
        { label: 'supplier', value: 'supplier' },
        { label: 'partner', value: 'partner' },
        { label: 'employee', value: 'employee' }]"/>

<lightning:dualListbox name="multipleOptions" 
                           label= "relationship" 
                           sourceLabel="available" 
                           selectedLabel="checked" 
                           options="{!v.RelationshipWithea_Options}" 
                           value="{!v.accountRecord.ea_Relationship_with_EA__c}"/>

and on my controller i use

var eaRel = component.get("v.accountRecord.ea_Relationship__c");
        var str='';
        eaRel.forEach(function(item){
            str=str+item+";";
        }, this);
        component.set("v.accountRecord.ea_Relationship__c", str);

The thing is that when controller is called (after a button is clicked), i see on my browser console the following error:

Uncaught (in promise) TypeError: this.value.forEach is not a function
at M.get computedSelectedList [as computedSelectedList] (dualListbox.js:2)
at w (dualListbox.js:2)
at mo (aura_prod.js:3)
at yr (aura_prod.js:3)
at bo (aura_prod.js:3)
at aura_prod.js:3
at To (aura_prod.js:3)
at cr (aura_prod.js:3)
at Array.ir (aura_prod.js:3)
at Bt (aura_prod.js:3)

and after that, i cannot edit my dualListBox component... Any suggestions?

  • so your error occurred immediately after option click on duallist? – sdandamud1 Nov 20 '19 at 14:58
  • No, but it could. The error occured immediately after the controller section that i posted is called/executed – Giorgos Galaios Nov 20 '19 at 15:02
  • which event triggers controller section of code which u posted, i feel your not added all your code, please update your question – sdandamud1 Nov 20 '19 at 15:38
1

You are grabbing your dualListBox element incorrectly. You need to set an aura:id on it and then you can use cmp.find(). Here is an example:

<aura:attribute name="RelationshipWithea_Options" type="List" default="[
        { label: 'supplier', value: 'supplier' },
        { label: 'partner', value: 'partner' },
        { label: 'employee', value: 'employee' }]"/>
<aura:attribute name="values" type="List" default="['supplier','partner']"/>

<lightning:dualListbox aura:id="selectOptions"
                       name="multipleOptions" 
                           label= "relationship" 
                           sourceLabel="available" 
                           selectedLabel="checked" 
                           options="{!v.RelationshipWithea_Options}"
                           value="{!v.values}"/>

controller:

someAction : function(cmp, evt, help) {
     var arryOfSelVals = component.find('selectOptions').get('v.value');
     var strOfVals = arryOfSelVals.join(';'); // returns 'supplier;partner'

    }

//Call this function onload of AccountRecord to set values
loadExistingValues : function(cmp,evt,help)
{
     var existStr = cmp.get('v.accountRecord.ea_Relationship_with_EA__c')
     var arryVals = existStr.split(';');
     cmp.set('v.values',arryVals)

}
  • Hi Bryan and thanks for your response. I tried this, it works fine for create new Account. But what about edit? I this case i need to load the values that the Account has and show them to the user. So i need somehow to have the value="v.accountRecord.ea_Relationship_with_EA__c" – Giorgos Galaios Nov 20 '19 at 16:06
  • @GiorgosGalaios are you saying load the values from your custom field so they appropriately already appear in the selected and available columns? – Bryan Anderson Nov 20 '19 at 16:13
  • Yes, this is it! – Giorgos Galaios Nov 20 '19 at 16:14
  • @GiorgosGalaios I have updated my answer – Bryan Anderson Nov 20 '19 at 16:23
  • 1
    You made my day, mate! You are amazing, thank you!!! – Giorgos Galaios Nov 20 '19 at 18:29

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.