feat: Settings: enable Save button only if changes has been made

This commit is contained in:
slawkens 2025-02-02 22:04:37 +01:00
parent 4fda4f643b
commit 28fef952f8

View File

@ -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(); e.preventDefault();
$.ajax({ $.ajax({
@ -94,6 +113,13 @@
duration: 3000, duration: 3000,
escapeMarkup: false, escapeMarkup: false,
}).showToast(); }).showToast();
let $settings = $('#settings');
$settings.data('serialized', $settings.serialize());
$settings
.find('input:submit, button:submit')
.prop('disabled', true)
.prop('title', noChangesText);
}, },
error : function(response) { error : function(response) {
Toastify({ Toastify({
@ -109,6 +135,7 @@
}); });
}); });
</script> </script>
<script> <script>
{% for key, value in settings %} {% for key, value in settings %}
{% if value.type == 'password' %} {% if value.type == 'password' %}