Skip to content

Commit 3fe9646

Browse files
lukbukkitlunny
authored andcommitted
Enabling and disabling the commit button to prevent empty commits (web editor) (#8590)
* Enabling and disabling the commit button to prevent empty commits Signed-off-by: LukBukkit <[email protected]> * The button won't get enabled if you change the commit message Signed-off-by: LukBukkit <[email protected]> * Fixes a spelling mistake for 'silent' Signed-off-by: LukBukkit <[email protected]>
1 parent fe41f71 commit 3fe9646

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

public/js/index.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,27 @@ 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+
const dirtyFileClass = 'dirty-file';
1580+
1581+
// Disabling the button at the start
1582+
$commitButton.prop('disabled', true);
1583+
1584+
// Registering a custom listener for the file path and the file content
1585+
$editForm.areYouSure({
1586+
silent: true,
1587+
dirtyClass: dirtyFileClass,
1588+
fieldSelector: ':input:not(.commit-form-wrapper :input)',
1589+
change: function () {
1590+
const dirty = $(this).hasClass(dirtyFileClass);
1591+
$commitButton.prop('disabled', !dirty);
1592+
}
1593+
});
1594+
1595+
$commitButton.click(function (event) {
15761596
// A modal which asks if an empty file should be committed
15771597
if ($editArea.val().length === 0) {
15781598
$('#edit-empty-content-modal').modal({

0 commit comments

Comments
 (0)