• Brenda Paiva 3
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 0
    Replies
Hello, everyone. 

I have a parent component, with a child component to simulate a multipicklist selection. I have to pass the list of selected values to the parent component, but it doesn't work. Does enyone know how to solve this? 

Child component:
<aura:attribute name="UFList" type="List" default="[]"/>
    <aura:attribute name="selectedUFList" type="List"  default="[]"/>
     
    <div class="slds-m-around_xx-small">
        <lightning:dualListbox aura:id="selectUF"
                               name="UF"
                               sourceLabel="Disponíveis"
                               selectedLabel="Selecionados"
                               options="{!v.UFList }"
                               value="{!v.selectedUFList}"
                               onchange="{!c.handleUFChange}"/>
        <lightning:button variant="brand" label="Salvar" onclick="{!c.getSelectedUF}" />
    </div>

Child controller:
getSelectedUF : function(component, event, helper){
        var selectedValues = component.get("v.selectedUFList");
        var componentEvent = component.getEvent("MultiPicklitsEvt");
            
            componentEvent.setParams({
                "UFVar" : component.get("v.selectedValues"),
            });
            
            componentEvent.fire();
        }


Event:
<aura:event type="COMPONENT"  >
    <aura:attribute name="UFVar" type="String"  />
</aura:event>

Parent component:
 <aura:handler name="MultiPicklitsEvt" event="c:MultiPicklitsEvt" action="{!c.handleMultiPicklitsEvt}"/>

Parent Controller:
handleMultiPicklitsEvt : function (component,event,helper) {
        
        var item = component.get("v.item");
        component.set("v.chosenUF", event.getParam("UFVar"));
        console.log(UFVar)
        
        item.UF__c = event.getParam("UFVar");
        log.console(chosenSP)
        
        component.set("v.item", item);     
    },
    
Hello, everyone. 
I have 2 different functions in my lookup component. The first loads the records (doinit) and another fires an event to pass to the parent component the chosen record Id and label.

1) loadValues : function (component, event) {
        var record = component.get("v.record");
        var subheading = '';
        for(var i=0; i<component.get("v.subHeadingFieldsAPI").length ;i++ ){
            if(record[component.get("v.subHeadingFieldsAPI")[i]]){
                subheading = subheading + record[component.get("v.subHeadingFieldsAPI")[i]] + ' • ';
            }
        }
        
        subheading = subheading.substring(0,subheading.lastIndexOf('•'));
        component.set("v.subHeadingFieldValues", subheading);
        console.log('check')
    },

2) choose : function (component,event) {
        var chooseEvent = component.getEvent("lookupChoose");
        chooseEvent.setParams({
            "recordId" : component.get("v.record").Id,
            "recordLabel":component.get("v.record").Name
        });
        chooseEvent.fire();
        console.log('event fired');
    }

the problem is: I have to make those things happen at the same time. I've tried to fire the event in the first function but it didn't work, so I thought in calling the function "choose" inside the "load Values". Can anyone help me with that?