0

I am updating a value for a record using lightning-record-edit-form update in the child component. After updating the record, I want to pass the updated record to the parent. It is not get passed when firing the custom event.

Child LWC HTML:

<lightning-record-edit-form record-id={accRecord.Id} object-api-name="Account" onsuccess={handleSuccess}>

Child LWC JS

handleSuccess(){
    console.log('IN SUCCESS'+this.accRecord);
    const event = new CustomEvent('child', {
        // detail contains only primitives
        detail: {key1:accRecord,key2:"Driller"}
        });
        this.dispatchEvent(event);
}

Parent HTML:

<c-account-details onchild={haldleChild}></c-account-details>

Parent JS:

 haldleChild(event){
    console.log('=======in Parent from child=='); 
    this.salesfrocedriller=event.detail.key1 +' '+event.detail.key2;
}

Please let me know the issue.

1 Answer 1

3
detail: {key1:accRecord,key2:"Driller"}

Should be:

detail: {key1:this.accRecord,key2:"Driller"}

To access class-level variables, you need to use this.

Note that the Id isn't automatically set, you may want to do that, as well:

handleSuccess(event){
    this.accRecord.id = event.detail.id
    const event = new CustomEvent('child', {
        // detail contains only primitives
        detail: {key1:this.accRecord,key2:"Driller"}
        });
        this.dispatchEvent(event);
}

You must log in to answer this question.

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