Skip to content

Commit

Permalink
Enabling and disabling the commit button to prevent empty commits
Browse files Browse the repository at this point in the history
Signed-off-by: LukBukkit <luk.bukkit@gmail.com>
  • Loading branch information
lukbukkit committed Oct 20, 2019
1 parent 85e4190 commit ddd657d
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,21 @@ 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');

// Disabling the button at the start
$commitButton.prop('disabled', true);
$editForm.on('dirty.areYouSure', function() {
$commitButton.prop('disabled', false);
});
$editForm.on('clean.areYouSure', function() {
$commitButton.prop('disabled', true);
});

$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 ddd657d

Please sign in to comment.