You need to sign in to do that
Don't have an account?
Venkat 163
how to make input field required ( using <lightning:inputfield />) in lightning
I am using <lightning:inputField /> for creating input field in component,I want make input is required or mandatory in lightning component.
Please provide sample code or solution around above senario.
Please provide sample code or solution around above senario.
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"/>
</aura:component>
Your Answer work for <lightning:input >,
but I am looking for <lightning:inputField >, in <lightning:inputField > "required" attribute not supporting ,so If you have any customized validation code for <lightning:inputField > Plesae let me know.
var caseRec = component.get("v.caseRec");
if($A.util.isEmpty(caseRec.Subject) || $A.util.isUndefined(caseRec.Subject)){
alert('Subject is Required');
return;
}
Hi Venket,
You are not able to use validity on lightning:inputField because the attribute is not supported on this component, instead its an attribute for lighting:input.
For validating lightning:inputField , you can refer to
https://salesforce.stackexchange.com/questions/213804/how-can-one-validate-recordeditform-fields-before-submitting-them-to-the-platf/213905#213905 link provides a perspective as how you can validate values entered on the component.
It puts a red asterisk against the field.
You can validate either on the field changing, or on submission of the record.