Saturday, May 25, 2019

Lightning:recordEditForm

Lightning:recordEditForm is used to display one or more fields related to the record by accepting record Id. We use lightning:inputField inside the lightning:recordEditForm to create editable fields. We can use lightning:outputField as well to display read-only information.

lightning:recordEditForm supports the below features:


  1. Display a record edit layout for editing a specified record.
  2. Display a record create layout for creating a new record.


Editing a Record:

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
    <lightning:recordEditForm recordId="{!v.recordId}" objectApiName="Account">
        <lightning:messages />
        <lightning:outputField fieldName="Name" />
        <lightning:inputField fieldName="Description" />
        <lightning:inputField fieldName="Industry" />
        <lightning:inputField fieldName="Site" />
        <lightning:button class="slds-m-top_small" variant="brand" type="submit" name="update" label="Update" />
    </lightning:recordEditForm>
</aura:component>


Creating a Record:

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
    <lightning:recordEditForm  objectApiName="Account">
       <lightning:messages />
        <lightning:inputField fieldName="Name" />
        <lightning:button class="slds-m-top_small" type="submit" label="Create New Account" />
    </lightning:recordEditForm>
</aura:component>

Note:

1) Not all standard object are supported.
For ex: Event and task.

2) If a lightning:button component with type="submit" is provided for the record edit layout  or record create layout and it's clicked,the component automatically performs error handling.

3)The field-level security and sharing are taken into consideration by this component so user will only see
the data they have access to.

4) We use lightning:messages as described in the above examples to display error messages in the UI.

5) The form does not displays Submit and Cancel buttons.


Some additional events supported are below:

      onload: The action triggered when the form data is loaded.

      onsubmit:The action triggered when the form is submitted.

onsuccess:The action triggered when the form is saved.

       onerror:The action triggered when there is an error on form 
submission.

No comments:

Post a Comment