Disable save button when save is executed

htmljavascriptlightning-web-components

I'm new to Salesforce Development.
I'm stuck in my code from past few hours.

I would like to disable the button after record is saved and it should enable when the user enters another values in the field.

I have researched about it but got nothing on web.

Here's my HTML

<div class="slds-text-align_center">
    <lightning-button
        label="Save"
        onclick={handleTimesheet}
        disabled={disableButton}
    ></lightning-button>
</div>

In JS,button is disabled when the last name is empty, I want this as well as, disable the button when the save is executed.

get disableButton() {
    return !this.lastName;
}

It would be a great help.

Thank in advance.

Best Answer

I am still learning the lwc. :) But let me give it a try.
Define a boolean variable called as isSaved. Set it to false initially. Change your disableButton method like this:

get disableButton() {
    return !this.lastName || this.isSaved;
}

Then in the Save method, when you have a success, just set the isSaved as true like this:

this.isSaved=true;