You need to sign in to do that
Don't have an account?
Update values via Lightning-record-edit-form - Issue
Hi,
I have used Lightning-record-edit-form to update values of existing records. The issue is that when clicking on the Update Record button, nothing change. I am not sre what I am doing wrong. I have got this code below:
Java Script:
handleSubmitUpdate(event){
const fields = event.detail.fields;
this.template.querySelector('lightning-record-edit-form').submit(fields);
}
handleSucessUpdate(event){
const updatedRecord = event.detail.fields;
console.log('onsuccess: ', inputField);
}
HTML:
<template if:true={selectedEvent} >
<section role="dialog" tabindex="-1" class="slds-modal slds-fade-in-open slds-modal_small"
aria-labelledby="modal-heading-01" aria-modal="true" aria-describedby="modal-content-id-1">
<div class="slds-modal__container">
<header class="slds-modal__header">
<span class="slds-modal__close">
</span>
<h2 class="slds-text-heading_medium slds-hyphenate">{selectedEvent.title}</h2>
</header>
<div class="slds-modal__content slds-p-around_medium">
<lightning-record-edit-form object-api-name="Event_Calendar__c" onsuccess={handleSuccessUpdate}
>
<!-- Include input fields for updating the record -->
<lightning-input-field field-name="Title__c" value={selectedEvent.title} data-field="Title" type="text"></lightning-input-field>
<lightning-input-field field-name="Type__c" value={selectedEvent.type} data-field="Type" type="picklist" ></lightning-input-field>
<lightning-button label="Cancel" title="Cancel" onclick={createCancelUpdate} class="slds-m-right_small"></lightning-button>
<lightning-button variant="brand" type="submit" label="Update Event" title="Update Event" onclick={handleSubmitUpdate}></lightning-button>
</lightning-record-edit-form>
</div>
</div>
</section>
<div class="slds-backdrop slds-backdrop_open"></div>
</template>
I am not sure what I am doing wrong
Based on the code you provided, it appears that there is a typo in your JavaScript code. In the handleSucessUpdate function, you're trying to access the event.detail.fields object using the variable name inputField, which is not defined. You should use the correct variable name updatedRecord instead.
Here's the corrected JavaScript code: Make sure to update your JavaScript code with the above corrections. After making this change, check the browser's console log to see if the updatedRecord object is logged correctly. This will help you verify that the record update is successfully happening.
Hope this helps !
Thank you.