[SalesForce] default lightning:inputField dependent picklist

In Visualforce/Standard Salesforce UI, if you have a required dependent picklist with only one value, it will default the field to that value and not allow the user to change the value.

Is there any way to replicate that functionality with lightning:input field? I know that we can get the picklist values in the apex controller but I'm hoping there's some way to get the filtered list based on the controlling field.

Best Answer

Refer to the sample code extract below from the documentation.

The lightning:inputField of the dependent required picklist field gets defaulted if a single value exist.

This example uses LeadSource as the controlling field and Level__c as the dependent field for a dependent picklist.

<lightning:recordEditForm aura:id="recordViewForm"
                                  recordId="{!v.recordId}"
                                  objectApiName="Contact">
    <lightning:messages />
    <!--Other fields here-->
    <lightning:inputField fieldName="LeadSource" />
    <lightning:inputField fieldName="Level__c" />
    <lightning:button aura:id="submit" type="submit" label="Update record" class="slds-m-top_medium"/>
</lightning:recordEditForm>
Related Topic