1

This question already has an answer here:

I have industry and subindustry picklists in classic but i want to work these picklists in lightning component. I have created controlling picklist but not able to fetch related values of dependent picklist. Please help.

Code is-

<aura:component Controller="BPValueCalController">
    <aura:attribute name="valueCalculator" type="Value_Calculator__c[]"/>
    <aura:attribute Name="NewValueCalculator"  type="Value_Calculator__c"
        default="{ 'sobjectType': 'Value_Calculator__c',
                    'Name':'',
                    'Picture__c' :'',
                    'Industry__c' :''
                 }"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:attribute Name="value" type="String"/>
    <div class="Container">
        <form class="slds-form--small">
            <div class="slds-form-element__control">
                <div class="slds-select_container">
                    <ui:inputSelect label="Industry" class="dynamic" 
                                    aura:id="InputSelectDynamic" 
                                    value="{!v.NewValueCalculator.Industry__c}" 
                                    required="false"
                                    change="{!c.onSelectChange}"/>
                </div>
               <div class="slds-select_container">
                    <ui:inputSelect label="Sub Industry" class="dynamic" 
                                    aura:id="subIndustry" 
                                    value="{!v.NewValueCalculator.Sub_Industry__c}" 
                                    required="false"
                                    change="{!c.handleIndustryChange}"/>
                </div>

</div>
        </form>
    </div>
</aura:component>

Controller code-

public class BPValueCalController {
    @AuraEnabled
    public static List<String> getValueCal(){
        List<String> options = new List<String>();
        Schema.DescribeFieldResult fieldResult = Value_Calculator__c.Industry__c.getDescribe();
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
            for (Schema.PicklistEntry f: ple) {
                options.add(f.getLabel());
            }
        return options;
    } 


}

Controller.js code-

({
    doInit : function(component, event, helper) {
        var action = component.get("c.getValueCal");


        var inputsel = component.find("InputSelectDynamic");

        var opts=[];
        action.setCallback(this, function(a){
            for(var i=0;i< a.getReturnValue().length;i++){
                opts.push({"class": "optionClass", label: a.getReturnValue()[i], value: a.getReturnValue()[i]});
            }
            inputsel.set("v.options", opts);

        });

        $A.enqueueAction(action); 

    },

    onSelectChange : function(component, event, helper){
        var selected = component.find("InputSelectDynamic").get("v.value");
        alert(selected);
        console.log('selected');

    },

})

marked as duplicate by martin, Dave Humm, Mohith Shrivastava, Eric, Tushar Sharma Feb 10 '17 at 5:08

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.