How to use onsuccess action in lightning-record-edit-form?

Sample Code:

Lightning Web Component:


  1. <template>  
  2.   
  3.     <lightning-record-edit-form record-id="0013i000003DPlvAAG"  
  4.                                 object-api-name="Account"  
  5.                                 onsuccess={handleSuccess}>  
  6.   
  7.         <lightning-messages></lightning-messages>  
  8.         <lightning-output-field field-name="Name"></lightning-output-field>  
  9.         <lightning-input-field field-name="Industry"></lightning-input-field>  
  10.         <lightning-input-field field-name="Description"></lightning-input-field>  
  11.         <lightning-input-field field-name="Rating"></lightning-input-field>  
  12.         <lightning-button class="slds-m-top_small"  
  13.                           variant="brand"  
  14.                           type="submit"  
  15.                           name="update"  
  16.                           label="Update">  
  17.         </lightning-button>  
  18.   
  19.     </lightning-record-edit-form>      
  20.       
  21. </template>  

Lightning Web Component Controller:


  1. import { LightningElement } from 'lwc';  
  2.   
  3. export default class AccountEditLWC extends LightningElement {  
  4.   
  5.     handleSuccess( event ) {  
  6.   
  7.         const payload = event.detail;  
  8.         alert( JSON.stringify( payload ) );  
  9.   
  10.     }  
  11.   
  12. }  

Output:


No comments:

Post a Comment