From ddd657ddf26ba8d320496520d99e84e856b7af92 Mon Sep 17 00:00:00 2001 From: LukBukkit Date: Sun, 20 Oct 2019 17:44:59 +0200 Subject: [PATCH] Enabling and disabling the commit button to prevent empty commits Signed-off-by: LukBukkit --- public/js/index.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/public/js/index.js b/public/js/index.js index a903b219e712..b0bb143123c6 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -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({