6

I am creating a lightning component which shows opportunity in edit mode using lightning:recordform tag(summer 18 salesforce release). Now when I am clicking on cancel button it should close the quick action dialogue but it is displaying the same record in view mode on same quick action dialogue.

Edit form using lightning:recordform

After clicking cancel button on screen

code sample :

<lightning:recordForm 
     recordId="{!v.recordId}" 
     objectApiName="Opportunity" 
     layoutType="Full" 
     columns="2"
     mode="edit"
     onsubmit="{!c.handleSubmit}"/>

3 Answers 3

5

You need to add "oncancel" as an attribute:

<lightning:recordForm 
 recordId="{!v.recordId}" 
 objectApiName="Opportunity" 
 layoutType="Full" 
 columns="2"
 mode="edit"
 onsubmit="{!c.handleSubmit}"
 oncancel="{!c.handleCancel}"/>

For some reason it is not in their documentation which can be found here but it works for me!

Hopefully this solves your issue.

1

You need to implement lightning:recordEditForm specifically and manually handle the cancel button with a lightning:button.

Per the current spec, there isn't a way to override the default actions within lightning:recordForm.

Edit: This is theoretical, I don't know if this will work but it could

Given the following setup:

<aura:attribute name="formMode" type="String" default="edit"/>

<lightning:recordForm 
     recordId="{!v.recordId}" 
     objectApiName="Opportunity" 
     layoutType="Full" 
     columns="2"
     mode="{! v.formMode }"
     onsubmit="{!c.handleSubmit}"/>

<aura:handler name="change" value="{! v.formMode }" action="{! c.handleFormModeChange }"/>

You might be able to listen to a mode change and fire the close event manually. I bet you're going to get a bit of lag though since it takes a millisecond for the change handler to process.

1
  • 2
    it doesn't work for me
    – Aequitas
    Jul 25, 2018 at 3:02
0

Add on oncancel function to the lightning:recordForm

<lightning:recordForm 
     recordId="{!v.recordId}" 
     objectApiName="Opportunity" 
     layoutType="Full" 
     columns="2"
     mode="{! v.formMode }"
     onsubmit="{!c.handleSubmit}"
     oncancle="{!c.handleCancel}"
/>

Then perform this action in the controller

handleCancel : function(cmp, evt, hlp) {
    var url = window.location.href;
    var value = url.substr(0,url.lastIndexOf('/') + 1);
    window.history.back();
    return false;
}

You must log in to answer this question.

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