We have created a lighting component using "lightning:recordform" to display fields. This does not display standard buttons. Is there a way of also displaying standard buttons?
2 Answers
The view mode loads the form using output fields with inline editing enabled. You can edit fields that are marked updateable in the User Interface API. If the user clicks an edit icon next to a field, all fields that are updateable become editable, and the form displays Submit and Cancel buttons.
So, basically when you are using view
mode, you cant see any buttons. But in edit
mode you will Submit
and Cancel
.
Work around:
Note: mode
on recordForm is 1-way binding. So we need to implement some logic to come around that limitation which is implemented in example below
cmp:
<aura:component implements="lightning:isUrlAddressable" access = "GLOBAL">
<aura:attribute name="mode" type="String" default="view" />
<aura:attribute name="showEditBtn" type="Boolean" default="true" />
<aura:attribute name="initDone" type="Boolean" default="false" />
<div class="slds-theme_default">
<lightning:recordForm recordId="00128XXXXXXXXXX"
objectApiName="Account"
layoutType="Full"
onload="{!c.handleLoad}"
columns="2"
mode="{!v.mode}"/>
<aura:if isTrue="{!v.showEditBtn}">
<div class="slds-align_absolute-center slds-p-around_large">
<lightning:button label="Edit" onclick="{!c.doEdit}" />
</div>
</aura:if>
</div>
</aura:component>
and its JS:
({
doEdit : function(component, event, helper) {
component.set("v.mode","view"); // this is needed because mode on recordForm is 1-way binding
component.set("v.mode","edit");
component.set("v.initDone",true);
},
handleLoad : function(component, event, helper) {
console.log("loaded record form");
component.set("v.showEditBtn",!component.get("v.showEditBtn"));
}
})
There is no out-of-the-box component to display the actions.
You can query the available buttons using the below query and implement them yourself on the component using the "lightning:buttonGroup" and "lightning:button" components:
SELECT ExternalId, ActionTargetType, ActionTarget, ApiName, Category, ConfirmationMessage, GroupId, IconUrl, IconContentType, IconHeight, IconWidth, PrimaryColor, InvocationStatus, InvokedByUserId, IsGroupDefault, Label, Subtype, SourceEntity, Type, TargetUrl
FROM PlatformAction
WHERE SourceEntity = :objectApiName
AND ActionListContext = 'Record' AND TYPE IN ('QuickAction', 'StandardButton', 'CustomButton')
Platform action documentation: https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_platformaction.htm