Skip to content

Commit ddd657d

Browse files
committed
Enabling and disabling the commit button to prevent empty commits
Signed-off-by: LukBukkit <[email protected]>
1 parent 85e4190 commit ddd657d

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

public/js/index.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,21 @@ function initEditor() {
15721572
});
15731573
}).trigger('keyup');
15741574

1575-
$('#commit-button').click(function (event) {
1575+
// Using events from https://github.com/codedance/jquery.AreYouSure#advanced-usage
1576+
// to enable or disable the commit button
1577+
const $commitButton = $('#commit-button');
1578+
const $editForm = $('.ui.edit.form');
1579+
1580+
// Disabling the button at the start
1581+
$commitButton.prop('disabled', true);
1582+
$editForm.on('dirty.areYouSure', function() {
1583+
$commitButton.prop('disabled', false);
1584+
});
1585+
$editForm.on('clean.areYouSure', function() {
1586+
$commitButton.prop('disabled', true);
1587+
});
1588+
1589+
$commitButton.click(function (event) {
15761590
// A modal which asks if an empty file should be committed
15771591
if ($editArea.val().length === 0) {
15781592
$('#edit-empty-content-modal').modal({

0 commit comments

Comments
 (0)