From 28fef952f857b79d64bc7495ffa5e1999e68e192 Mon Sep 17 00:00:00 2001 From: slawkens Date: Sun, 2 Feb 2025 22:04:37 +0100 Subject: [PATCH] feat: Settings: enable Save button only if changes has been made --- system/templates/admin.settings.html.twig | 29 ++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/system/templates/admin.settings.html.twig b/system/templates/admin.settings.html.twig index e0f5d94b..7982780d 100644 --- a/system/templates/admin.settings.html.twig +++ b/system/templates/admin.settings.html.twig @@ -80,7 +80,26 @@ } }); - $('#settings').submit(function(e) { + const noChangesText = "No changes has been made"; + + $('form') + .each(function(){ + $(this).data('serialized', $(this).serialize()) + }) + .on('change input', function(){ + const disable = $(this).serialize() === $(this).data('serialized'); + $(this) + .find('input:submit, button:submit') + .prop('disabled', disable) + .prop('title', disable ? noChangesText : '') + ; + }) + .find('input:submit, button:submit') + .prop('disabled', true) + .prop('title', noChangesText) + ; + + $('#settings').on('submit', function(e) { e.preventDefault(); $.ajax({ @@ -94,6 +113,13 @@ duration: 3000, escapeMarkup: false, }).showToast(); + + let $settings = $('#settings'); + $settings.data('serialized', $settings.serialize()); + $settings + .find('input:submit, button:submit') + .prop('disabled', true) + .prop('title', noChangesText); }, error : function(response) { Toastify({ @@ -109,6 +135,7 @@ }); }); +