Use the lightning:recordForm
component to quickly create forms to add, view, or update a record.
Using this component to create record forms is easier than building forms manually with lightning:recordEditForm
or lightning:recordViewForm
. The lightning:recordForm
component provides these helpful features:
- Switches between view and edit modes automatically when the user begins editing a field in a view form
- Provides default Cancel and Save buttons in edit forms
- Uses the object’s default record layout with support for multiple columns
- Loads all fields in the object’s compact or full layout, or only the fields you specify
However, lightning:recordForm
is less customizable. To customize the form layout or provide custom rendering of record data, use lightning:recordEditForm
(add or update a record) and lightning:recordViewForm
(view a record).
The objectApiName
attribute is always required, and the recordId
is required only when you’re editing or viewing a record.
Lightining : recordForm
);
({
handleSuccess : function(cmp, event, helper) {
event.preventDefault();
const fields = event.getParam('fields');
fields.LastName = 'My Last Name';
cmp.find('RecordForm').submit(fields);
}
})
Output

Lightling :RecordEdit Form
({
handleCreateLoad : function(component, event, helper) {
var nameFieldValue = component.find("nameField").set("v.value", "My New Contact");
cmp.find('recordEditForm').submit(fields);
}
})
Output

Lightining : RecordView Form
Output
