1

I have an LWC component which has a lighting datatable component. I need to validate unsaved changes in this table, so I use the validate callback to check if there are any unsaved changes, and return an error if there are. Therefore stopping the user from going to the next screen if they have unsaved changes.

My validate method (simplified) looks like this:

@api
validate() {
    
    // unsaved changes
    if (this.draftValues.length) {
        return {
            isValid: false,
            errorMessage: 'Please save your changes before clicking next.'
        };
    }
    return { isValid: true };
}

And here is my function that gets called when you click cancel:

handleCancel(event) {
    const attributeChangeEvent = new FlowAttributeChangeEvent(
        'draftValues',
        this.draftValues
    );
    this.dispatchEvent(attributeChangeEvent); 
}

I've tried using FlowAttributeChangeEvent but the validate callback is never executed here.

How can I have the validate method triggered correctly (obviously I can't just do this.validate()) when the user clicks cancel, in order to remove the error message I added in the first place.

2
  • Hi, @ViqMontana, were you able to do this? Commented Jan 26, 2023 at 15:17
  • @SergioAndresPedrazaJerez I think my solution in the end was to set this.errors.rows = {}; in the cancel function. I wasn't able to call the 'validate` function manually.
    – ViqMontana
    Commented Jan 27, 2023 at 10:19

0

You must log in to answer this question.

Browse other questions tagged .