function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
HNT_NeoHNT_Neo 

Prevent JS Controller Save button from being able to be clicked multiple times

I have created a save button using js lightning controller, but am running into an issue where a user is able to click the Save button multiple times, creating multiple duplication of a new record. I disabled the popup window that confirms the save record (line 16 in code below). Is their a way to disable the save button after the user clicks on it once, then as the record uploads and saves into Salesforce and the table refreshes, have the save button refresh in order to re-appear? 
 
({
    doInit: function(component, event, helper) {
        helper.createObjectData(component, event);
    },
    Save: function(component, event, helper) {
        if (helper.validateRequired(component, event)) {
            var action = component.get("c.saveContacts");
            action.setParams({
                "ListContact": component.get("v.contactList")
            });
            action.setCallback(this, function(response) {
                var state = response.getState();
                if (state === "SUCCESS") {
                    component.set("v.contactList", []);
                    helper.createObjectData(component, event);
            //        alert('Contact Record Saved');                    
                }
            });
            $A.enqueueAction(action);
        }
    },
    addNewRow: function(component, event, helper) {
        helper.createObjectData(component, event);
    },
    removeDeletedRow: function(component, event, helper) {
        var index = event.getParam("indexVar");
        var AllRowsList = component.get("v.contactList");
        AllRowsList.splice(index, 1);
        component.set("v.contactList", AllRowsList);
    },
})

 
Greg CooganGreg Coogan
You could disable or hide the button on-click. After save is completed, rerender the table and enable the button again in JS.

Another approach is set a variable in a helper class that is set to true when the user first presses the button. If they click it again, you prevent the creation of the record because that global variable is set to true.

This should also help:
https://salesforce.stackexchange.com/a/10051