1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-22 12:54:53 -05:00

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 <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>
This commit is contained in:
Lukas 2019-10-23 02:29:33 +02:00 committed by Lunny Xiao
parent fe41f71ba1
commit 3fe9646564

View file

@ -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({