+ Start a Discussion
Firas Taamallah 18Firas Taamallah 18 

How to make field mandatory for certain recordType using Aura component?

Hello ,

There's Page layout which contain many component in , the goal is to make field (which is present in some of component) Mandatory for certain RecordType - How can i achieve this ? 

Using Aura:if ?
AnudeepAnudeep (Salesforce Developers) 
You can make the field required with the required attribute in your lightning component

lightning:inputField

The following attribute is new.

required—To make an input field required only on the client, set required to true. Use this attribute to require a value in a field before the form can be submitted, and the field isn’t marked required in Setup. If the field doesn’t have a value, the component’s client-side validation catches the error before the form data is submitted to the server.

Please see this documentation to learn more

Also, see this post where a similar discussion is made

Let me know if this helps. If it does, please mark this answer as Best. It may help others in the community. Thank You!
AnudeepAnudeep (Salesforce Developers) 
//Sample code showing required attribute. You need to add <aura:if> here

 <lightning:recordEditForm recordId ="{!v.recordId}" objectApiName = "Case" aura:id="leadCreateForm" onsubmit="{!c.handleSubmit5}" >
        <lightning:messages />
                                
                                <lightning:inputField aura:id="bill" fieldName="Billing_Disposition__c" required ="true"/>
                               
                     
                                     
        <lightning:inputField aura:id="bill" fieldName="Billing_Hours__c" required ="true"/>
                               
                               
        <lightning:inputField aura:id="bill" fieldName="Billing_Comments__c" required ="true" />
                               
                                <br/>
                                <br/>
                                <br/>
                                
        
    </lightning:recordEditForm>

NOTE: The code provided is an example. You'll need to review and make modifications for your organization.