3

I am trying to create a service component as illustrated in Trailhead

https://trailhead.salesforce.com/trails/lex_dev/projects/workshop-override-standard-action/steps/override_2

In this module it was given for one field which works beautifully. But let's say I have 5 different picklist fields on the Lightning component UI. So in that situation I am trying accomplish the concept but stuck in how to define the aura:attribute. If I define the way it is given here it is retrieving the values for the last called "v.picklistValues" for all of the fields.

    <***** Picklist Component******>
<aura:component controller="PickListController" access="global" description="PickListValues">
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <aura:attribute name="sObjectName" type="String" />
    <aura:attribute name="fieldName" type="String" />
    <aura:attribute name="picklistValues" type="Object" />
</aura:component>

****Picklist Controller****
({  
    doInit : function(component) {
        var action = component.get("c.getPickListValuesIntoList");
        action.setParams({
            objectType: component.get("v.sObjectName"),
            selectedField: component.get("v.fieldName")
        });
        action.setCallback(this, function(response) {
            var list = response.getReturnValue();
            component.set("v.picklistValues", list);
        })
        $A.enqueueAction(action);
    }
})
    <***** Parent Component calling Picklist component******>
<c:PicklistValues sObjectName="Executive_Snapshot__c" fieldName="Field1" picklistValues="{!v.picklistValues}" />
<c:PicklistValues sObjectName="Executive_Snapshot__c" fieldName="Field2" picklistValues="{!v.picklistValues}" />

enter image description here

2

When you add following code

<c:PicklistValues sObjectName="Opportunity" fieldName="StageName" picklistValues="{!v.picklistValues}" />

you are passing picklistValues attribute from parent component

<aura:attribute name="picklistValues" type="Object" /> 

so if you want to add another one add another parent component attribute and pass that as parameter

<aura:attribute name="secondpicklistValues" type="Object" />

your component will look like this

<aura:component >
        <aura:attribute name="picklistValues" type="Object" />
        <aura:attribute name="secondpicklistValues" type="Object" />
        <c:PicklistValues sObjectName="Executive_Snapshot__c" fieldName="Field1" picklistValues="{!v.picklistValues}" />
<c:PicklistValues sObjectName="Executive_Snapshot__c" fieldName="Field2" picklistValues="{!v.secondpicklistValues}" />
</aura:component>
  • That worked. I missed to realize that I have to give the attribute in Parent component. Thanks for the help! – user28452 Aug 22 '17 at 15:04

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.