Skip to content

Commit 28fef95

Browse files
committed
feat: Settings: enable Save button only if changes has been made
1 parent 4fda4f6 commit 28fef95

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

system/templates/admin.settings.html.twig

+28-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,26 @@
8080
}
8181
});
8282
83-
$('#settings').submit(function(e) {
83+
const noChangesText = "No changes has been made";
84+
85+
$('form')
86+
.each(function(){
87+
$(this).data('serialized', $(this).serialize())
88+
})
89+
.on('change input', function(){
90+
const disable = $(this).serialize() === $(this).data('serialized');
91+
$(this)
92+
.find('input:submit, button:submit')
93+
.prop('disabled', disable)
94+
.prop('title', disable ? noChangesText : '')
95+
;
96+
})
97+
.find('input:submit, button:submit')
98+
.prop('disabled', true)
99+
.prop('title', noChangesText)
100+
;
101+
102+
$('#settings').on('submit', function(e) {
84103
e.preventDefault();
85104
86105
$.ajax({
@@ -94,6 +113,13 @@
94113
duration: 3000,
95114
escapeMarkup: false,
96115
}).showToast();
116+
117+
let $settings = $('#settings');
118+
$settings.data('serialized', $settings.serialize());
119+
$settings
120+
.find('input:submit, button:submit')
121+
.prop('disabled', true)
122+
.prop('title', noChangesText);
97123
},
98124
error : function(response) {
99125
Toastify({
@@ -109,6 +135,7 @@
109135
});
110136
});
111137
</script>
138+
112139
<script>
113140
{% for key, value in settings %}
114141
{% if value.type == 'password' %}

0 commit comments

Comments
 (0)