0

I need to make the Name field required on the lightning:recordEditForm. So I tried its onload event and recordUi parameter. But it didn't work. So I am wondering if it's even possible with recordUi?

component.cmp

<lightning:recordEditForm objectApiName="myObject__c" onload="{! c.handleOnload }" >
    <lightning:inputField aura:id="field" fieldName="Name" />
</lightning:recordEditForm>

controller.js

handleOnload: function(component, event, helper) {
    console.log("handleOnload");
    const recordUi = event.getParam("recordUi");

    recordUi.objectInfos["myObject__c"].fields.Name.required = true;
    recordUi.objectInfo.fields.Name.required = true;
}

1 Answer 1

1

Currently you cannot set the lighting:inputField ui to required. You can however update the CSS file and add the customRequired class to the field and it will mark it as required, I then handle the submit event and check to see if the required fields have been filled in

CSS

.THIS .customRequired{
    font-weight: 400; 
 } 

 .THIS .customRequired:before{    
     content: "*";
     margin: 0 0.125rem 0 0.125rem;
     color: rgb(194, 57, 52);
     float: left; 
 } 
2
  • Yeah, that's possible. But event with this approach user will not see the error text "Complete this field." under the input field as they generally get for required fields. I'd like to find some way that would give consistent behavior. See it at i.imgur.com/n0u1MFw.png
    – Eduard
    Commented Jun 5, 2019 at 16:32
  • Also HTML 5 required attribute won't be showed as well
    – Eduard
    Commented Jun 5, 2019 at 16:34

You must log in to answer this question.

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