[SalesForce] Dependent picklist does not get enabled when the parent picklist’s value is set through controller

I am using lightning:recordEditForm and listing the various field I need to create in lightning:inputField. Two of these are dependent picklists, meaning only if the parent picklist has been selected the child will get enabled with associated values. Here is the code;

<lightning:recordEditForm aura:id="contactCreateForm" objectApiName="Contact" recordTypeId="{!v.individualRecordTypeId}"
                        onsubmit="{!c.onSubmit}"
                        onload="{!c.onLoad}"
                        onsuccess="{!c.onSuccess}"
                        onerror="{!c.onError}"
                        >
                            <lightning:messages />
                            <lightning:inputField aura:id="ccf_FirstName" fieldName="FirstName" />
                            <lightning:inputField aura:id="ccf_LastName" fieldName="LastName" />

                            <lightning:inputField aura:id="ccf_nickname" fieldName="Nickname__c" />
                            <lightning:inputField aura:id="ccf_email" fieldName="Email" />

                            <lightning:inputField aura:id="ccf_ReportsToId" fieldName="ReportsToId" />
                            <lightning:inputField aura:id="ccf_Firm_Description__c" fieldName="Firm_Description__c" />
                            <lightning:inputField aura:id="ccf_Userclass__c" fieldName="Userclass__c" />
                            <div align="center">
                                <lightning:button class="slds-m-top_small" variant="brand" type="submit" label="Save" />
                                <lightning:button class="slds-m-top_small" variant="neutral" label="Cancel" onclick="{!c.handleCancel}" />
                            </div>
                        </lightning:recordEditForm

I am setting the value of the parent picklist in the onLoad() event of the lightning:recordEditForm. This gets populated in the UI as expected, however, on the population of parent picklist, I expect the child picklist to get enabled which does not happen.

 onLoad: function(component, event, helper){
   component.find("ccf_Firm_Description__c").set("v.value", component.get("v.accountObj.Location_Firm_Description__c"));
   component.find("ccf_Userclass__c").set("v.disabled",false);
 }

I want to make the child picklist enabled. I tried to set the v.disabled property of the lightning:inputField to false. This throws an internal error.

Error:

Uncaught render threw an error in 'lightning:inputField' [Cannot read property 'config' of undefined] 
throws at https://factset--devpro.lightning.force.com/auraFW/javascript/fm7mXFzeJAXPkqJAjx6Qpw/aura_proddebug.js:24283

I tried doing a $A.get('e.force:refreshView').fire(); on afterRender in the renderer. Doesn't work either. Using jQuery to enable it won't work either because of the locker service and disabling it for my org is not an option. I wanted to know if I'm missing something before raising a case with Salesforce.

Any help on how to enable the dependant picklist is much appreciated.

Best Answer

Sorry if my previous explanation wasn't clear. If we are going to set the value of master picklist using controllerJS, then it is recommended to rerender the dependant picklist for changing the dependant values.

i did this and it works !!

i set the value of refreshFlag to False before setting the master picklist field value and once it is done again i changed the boolean refreshFlag to True. THis rerender the dependant picklist component and the correct values gets reflected.

<!-- dependeant picklist goes here -->
<aura:if isTrue="{!v.refreshFag}">
  <lightning:inputField fieldname="dependantpicklist__c"/> 
</aura:if>
Related Topic