Skip to content

Commit

Permalink
fix(forms): prevent double submit on comment forms
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalsem committed Oct 5, 2023
1 parent fbd0385 commit 1b05718
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion views/default/elgg/comments.js
Expand Up @@ -15,6 +15,8 @@ define(['jquery', 'elgg'], function ($, elgg) {

$(document).on('submit', '.elgg-form-comment-save', function (event) {
var $form = $(this);

$form.find('.elgg-button-submit').prop('disabled', true);

require(['elgg/Ajax'], function(Ajax) {
var ajax = new Ajax();
Expand All @@ -39,6 +41,7 @@ define(['jquery', 'elgg'], function ($, elgg) {
}

if (!$container.length) {
$form.find('.elgg-button-submit').prop('disabled', true);
return;
}

Expand Down Expand Up @@ -75,8 +78,14 @@ define(['jquery', 'elgg'], function ($, elgg) {
$comment[0].scrollIntoView({behavior: 'smooth'});

fix_pagination($container);
},
error: function() {
$form.find('.elgg-button-submit').prop('disabled', false);
}
});
},
error: function () {
$form.find('.elgg-button-submit').prop('disabled', false);
}
});
});
Expand Down Expand Up @@ -167,7 +176,8 @@ define(['jquery', 'elgg'], function ($, elgg) {

submitForm: function () {
var $form = this.getForm();

$form.find('.elgg-button-submit').prop('disabled', true);

require(['elgg/Ajax'], function(Ajax) {
var ajax = new Ajax();

Expand All @@ -178,6 +188,9 @@ define(['jquery', 'elgg'], function ($, elgg) {
// Update list item content
$form.closest('.elgg-item-object-comment').html(result.output);
}
},
error: function() {
$form.find('.elgg-button-submit').prop('disabled', false);
}
});
});
Expand Down

0 comments on commit 1b05718

Please sign in to comment.