How to get field values in onsuccess method of lightning-record-edit-form?

Sample Code:

LWC HTML:

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

LWC JavaScript:

  1. import { LightningElement } from 'lwc';  
  2.   
  3. export default class Sample extends LightningElement {  
  4.   
  5.     handleSuccess( event ) {    
  6.     
  7.         const payload = event.detail;            
  8.         var objJSON = JSON.parse(JSON.stringify(payload));  
  9.         alert(objJSON["fields"]["Industry"]["value"]);    
  10.     
  11.     }  
  12.   
  13. }  

LWC meta.xml:

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">  
  3.     <apiVersion>47.0</apiVersion>  
  4.     <isExposed>false</isExposed>  
  5.     <targets>  
  6.         <target>lightning__Tab</target>  
  7.     </targets>  
  8. </LightningComponentBundle>  

Output:


No comments:

Post a Comment