+ Start a Discussion

make a non required field to be required in salesforce lighting web component

I would like to create lwc wherein I want to make some non- required fields as required whenever user does not enter a value. May be display with message or flag a lable.
VinayVinay (Salesforce Developers) 
You can use lightning-input-field to make field required.

Check below references.


Ashish Kumar YadavAshish Kumar Yadav
Hi CrmEditr,

add required="true" in your markup for input field.

<aura:component >
    <aura:attribute name="EmpName" type="String" default='' />
    <lightning:input label="Employee Name" value="{!v.EmpName}" required="true"/>

If it is work for you please mark as the best answer.if you face any problem let me know.