Disable save button in custom module

Hi everyone, I have a problem on a custom form, in some cases, when inserting, the insertion is duplicated.

I have checked the code several times and there are no duplicate calls and I don’t understand the reason for the duplication.

Sometimes it happens that the insertion time takes longer than expected (there are some checks to carry out) and during this time the “save” button remains active, if during this time I click on this button several times, duplication may occur.

How can I temporarily deactivate the “save” button, only after clicking it the first time?
Thank you.

Is this in editview? If so, JS is your answer, you could listen for the first click and then change the DIV where the button is to “hidden”. I insert JS into editview all the time, not specifically to hide the save button though, but sure it’s possible.

Am I remembering correctly or was there a method via view.edit? Without bothering js

I don’t really see how this would be possible without JS. You’d have to listen for the click and then hide the button. If there is another way to do this, I’d like to know too!

Create a custom boolean field in Studio named save_diabled or whatever. Create an after save logic hook that sets the value to 1 (true).

Add a check in the Display function of custom/YOUR MODULE/view.edit.php that both disables the button and gives a visual cue that it is disabled (eg. color change)

Note: This method ensures the save button remains disabled indefinitely unless changed in the database by an admin. You would not display this field in the edit view. Also, this doesn’t hide the button, but meets the same goal. Hiding the button I think would require accessing the display attribute, wherever that lives.