With the record:EditForm lightning base component, one can now easily ensure that picklist values are displayed dynamically based on the record type that is chosen.

Instead of having to leverage the UI API explicitly, all I need to do is have the following markup:

<aura:attribute name="RecordTypeId" type="String" access="public"/>
    <lightning:recordEditForm aura:id="recordEditForm" recordTypeId="{!v.RecordTypeId}" objectApiName="Interactions__c" class="slds-p-top_small"> 
        <lightning:inputField fieldName="Interaction_Category__c" />
        <lightning:inputField fieldName="RecordTypeId" value="{!v.RecordTypeId}" class="slds-hide" />          

and then in the .js controller, I can pass in the record type Id to the relevant value attribute like so:

    doInit : function(component, event, helper)
        var fullURL = window.location.href;
        var recordTypeId = fullURL.substring(fullURL.indexOf("recordTypeId") + 13,fullURL.indexOf("recordTypeId") + 31);
        console.log('recordTypeId is: ' + recordTypeId);
        if (recordTypeId != null) 
            component.set('v.RecordTypeId', recordTypeId); 

So now, the field 'Interaction Category' will dynamically display the picklist values that correspond to the selected record type of the sObject. This is very helpful.

However, unfortunately, as per the docs, there is no 'required' attribute for lightning:inputField. I could make the field itself required but I want to conditionally make it a required field.

I have been trying with setCustomValidity or set("v.errors") as per this example but nothing seems to be working - in the console.logs, I can't even get past the .setCustomValidity method.

What is the best approach to have a lighting:inputField component have error handling / conditional required rendering?

1 Answer 1


This is possible using the logic as outlined in this duplicate post here: How can one validate 'recordEditForm' fields before submitting them to the platform?. Lastly, this doc is also relevant: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_validate_fields.htm.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .