1

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.

1 Answer 1

3

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;
4
  • It's working on disable button after saving the button stays disable while creating another record. Commented Feb 18, 2022 at 10:15
  • 2
    @PrinceSharma You will also need to have code that detects a new change (e.g. an onchcnage handler) and re-sets this property to false.
    – Keith C
    Commented Feb 18, 2022 at 10:30
  • @KeithC it helped. Thank You! Commented Feb 18, 2022 at 11:12
  • 1
    @Shailesh instead of this.isSaved=true it should be this.isSaved=false. Thank you! Commented Feb 18, 2022 at 11:20

You must log in to answer this question.

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