From a15c2493b535094e57204d3162a4e93e0caaa856 Mon Sep 17 00:00:00 2001 From: scouzinier Date: Mon, 13 Apr 2026 11:34:42 +0200 Subject: [PATCH] disable submit button during form processing --- assets/js/app/ajax-save.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/assets/js/app/ajax-save.js b/assets/js/app/ajax-save.js index 2a0318591..d19fa8177 100644 --- a/assets/js/app/ajax-save.js +++ b/assets/js/app/ajax-save.js @@ -4,7 +4,8 @@ import { Toast } from 'bootstrap'; let form = $('#editcontent'); let record_id = form.data('record'); -let element = $('button[name="save"][type="button"]'); //type="button" because it should only work when ajaxy is enabled +let elementButton = $('button[name="save"][type="button"]'); //type="button" because it should only work when ajaxy is enabled +let elementSubmit = $('button[name="save"][type="submit"]'); //type="submit" for classic form POST let dom_element = '
'; @@ -28,7 +29,7 @@ $(document).ready(function() { } //it should only work when ajaxy is enabled - if (element.length) { + if (elementButton.length) { window.onbeforeunload = unloadPage; } @@ -64,16 +65,25 @@ $(document).ready(function() { let url = window.location.pathname; - element.on('click', function() { + // For classic POST: disable only after native HTML5 validation has passed (submit event) + if (elementSubmit.length) { + $(form).on('submit', function() { + elementSubmit.prop('disabled', true); + }); + } + + elementButton.on('click', function() { + elementButton.prop('disabled', true); $.ajax({ type: 'POST', link: url, data: $(form).serialize(), beforeSend: function() { - patience_virtue(element); + patience_virtue(elementButton); }, complete: function() { renable(); + elementButton.prop('disabled', false); }, success: function(data, textStatus) { if (!record_id) {