I Have written following code Component --
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:attribute name="country" type="Lead"/>
<ui:inputSelect label="Country" class="dynamic" aura:id="InputSelectDynamic" value="{!v.leadObj.Country__c}" change="{!c.onSelectChange}"/>
<aura:if isTrue="{!v.InputSelectDynamic != '--None--'}" >
<ui:inputSelect label="States" class="dynamic" aura:id="states" value="{!v.leadObj.States__c}" />
</aura:if>
Java Script Controller -
({
doInit : function(component, event, helper) {
var action = component.get("c.getLeadCountry");
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 action = component.get("c.getLeadState")
var inputsel = component.find("states");
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);
}
})
Apex Controller -
public class DependentPicklistDemoController {
@AuraEnabled
public static List<String> getLeadCountry(){
List<String> options = new List<String>();
options.add('--None--');
Schema.DescribeFieldResult fieldResult = lead.Country__c.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
for (Schema.PicklistEntry f: ple) {
options.add(f.getLabel());
}
return options;
}
@AuraEnabled
public static List<String> getLeadState(){
List<String> options = new List<String>();
Schema.DescribeFieldResult fieldResult = lead.States__c.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
for (Schema.PicklistEntry f: ple) {
options.add(f.getLabel());
}
return options;
}
}
I am not able to filter child picklist value on the basis of parent picklist values. Please help--