Skip to content

Commit

Permalink
Enabling and disabling the commit button to prevent empty commits (we…
Browse files Browse the repository at this point in the history
…b editor) (#8590)

* Enabling and disabling the commit button to prevent empty commits

Signed-off-by: LukBukkit <luk.bukkit@gmail.com>

* The button won't get enabled if you change the commit message

Signed-off-by: LukBukkit <luk.bukkit@gmail.com>

* Fixes a spelling mistake for 'silent'

Signed-off-by: LukBukkit <luk.bukkit@gmail.com>
  • Loading branch information
lukbukkit authored and lunny committed Oct 23, 2019
1 parent fe41f71 commit 3fe9646
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,27 @@ function initEditor() {
});
}).trigger('keyup');

$('#commit-button').click(function (event) {
// Using events from https://github.com/codedance/jquery.AreYouSure#advanced-usage
// to enable or disable the commit button
const $commitButton = $('#commit-button');
const $editForm = $('.ui.edit.form');
const dirtyFileClass = 'dirty-file';

// Disabling the button at the start
$commitButton.prop('disabled', true);

// Registering a custom listener for the file path and the file content
$editForm.areYouSure({
silent: true,
dirtyClass: dirtyFileClass,
fieldSelector: ':input:not(.commit-form-wrapper :input)',
change: function () {
const dirty = $(this).hasClass(dirtyFileClass);
$commitButton.prop('disabled', !dirty);
}
});

$commitButton.click(function (event) {
// A modal which asks if an empty file should be committed
if ($editArea.val().length === 0) {
$('#edit-empty-content-modal').modal({
Expand Down

0 comments on commit 3fe9646

Please sign in to comment.