0

I am trying to run an Event on my Child Component when the Datable row is selected on my Parent Component.
I am receiving the error below

Here is the Event code from my Child Component

handleCancel(event){
    const inputFields = this.template.querySelectorAll( 'lightning-input-field' );
    if ( inputFields ) {
        inputFields.forEach( field => {
        field.reset();
        this.showSaveButton = false;
        } );   
    }
}

Here is the Event code from my Parent Component

handleRowSelection(event){
        var selectedRows=event.detail.selectedRows;
        this.werRecordId = selectedRows[0].Id;
        this.template.querySelector('c-work-experience-record-page').handleCancel();
        this.werSelectedRow=true;
    }

Error

[NoErrorObjectAvailable] Script error.
a()@https://static.lightning.force.com/cs196/auraFW/javascript/nv49ahbZfs85wzJXOZaywA/aura_prod.js:1000:112
{anonymous}()@https://static.lightning.force.com/cs196/auraFW/javascript/nv49ahbZfs85wzJXOZaywA/aura_prod.js:1000:305
dispatchEvent()@https://static.lightning.force.com/cs196/auraFW/javascript/nv49ahbZfs85wzJXOZaywA/aura_prod.js:13:46387
Na.dispatchEvent()@https://static.lightning.force.com/cs196/auraFW/javascript/nv49ahbZfs85wzJXOZaywA/aura_prod.js:13:13839
Na.fireSelectedRowsChange()@https://falcon-pe--dxtest.sandbox.lightning.force.com/components/lightning/datatable.js:1:95086
Na.zn()@https://falcon-pe--dxtest.sandbox.lightning.force.com/components/lightning/datatable.js:1:49259
Na.handleSelectionCellClick()@https://falcon-pe--dxtest.sandbox.lightning.force.com/components/lightning/datatable.js:1:93785
6
  • What's the error you're getting? Please edit your question with more details.
    – Nick C
    Commented Nov 2, 2022 at 1:49
  • I have added the error Commented Nov 2, 2022 at 2:15
  • Is this line supposed to have two assignments? selectedRows=el.selectedRows=el.selectedRows.slice(1);
    – Nick C
    Commented Nov 2, 2022 at 2:42
  • I want to limit the selection to 1 row Commented Nov 2, 2022 at 2:49
  • Why are you querying the DOM for the rows? Couldn't you just do selectedRows = selectedRows[0]?
    – Nick C
    Commented Nov 2, 2022 at 4:40

1 Answer 1

0

I figured out the issue.... I forgot to add an @api decorator on the Event in my Child Component to expose it to the Parent.

@api
handleCancel(event){
    const inputFields = this.template.querySelectorAll( 'lightning-input-field' );
    if ( inputFields ) {
        inputFields.forEach( field => {
        field.reset();
        this.showSaveButton = false;
        } );   
    }
}

You must log in to answer this question.

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