Fix reset of defaults for text fields

Still need to address bindaddress:port and externalIP: Name
This commit is contained in:
stevenA 2021-12-31 15:01:02 +01:00
parent 8268bbf81a
commit 8953484e1f
2 changed files with 46 additions and 43 deletions

View file

@ -1192,16 +1192,18 @@ $(".sccp-restore").click(function() {
var edit_style = document.getElementById("edit_" + id).style; var edit_style = document.getElementById("edit_" + id).style;
if ($(this).data("type") === 'radio') { if ($(this).data("type") === 'radio') {
input = document.getElementsByName(id); input = document.getElementsByName(id);
} else if ($(this).data("type") === 'text') {
input = document.getElementsByName(id);
} }
if (input.length === 0) { if (input.length === 0) {
return; return;
} }
if ($(this).is(":checked")) { if ($(this).is(":checked")) {
console.log("Restore checked");
edit_style.display = 'block'; edit_style.display = 'block';
var defaultVal = $(this).data("default"); var defaultVal = $(this).data("default");
if ($(this).data("type") === 'radio') { if ($(this).data("type") === 'radio') {
// simulate read only for checkboxes // simulate read only for checkboxes except default
console.log(input);
input.forEach( input.forEach(
function(radioElement) { function(radioElement) {
radioElement.setAttribute('disabled', true); radioElement.setAttribute('disabled', true);
@ -1209,19 +1211,18 @@ $(".sccp-restore").click(function() {
radioElement.removeAttribute('disabled'); radioElement.removeAttribute('disabled');
radioElement.setAttribute('checked', true); radioElement.setAttribute('checked', true);
} else { } else {
radioElement.setAttribute('disabled', true);
radioElement.removeAttribute('checked'); radioElement.removeAttribute('checked');
} }
} }
); );
return; return;
} else if ($(this).data("type") === 'text') {
input[0].value = defaultVal;
input[0].readOnly = true;
} }
input.prop("readonly", true);
} else { } else {
console.log('restore/unchecked');
edit_style.display = 'none'; edit_style.display = 'none';
if ($(this).data("type") === 'radio') { if ($(this).data("type") === 'radio') {
// simulate read only for checkboxes
input.forEach( input.forEach(
function(radioElement) { function(radioElement) {
radioElement.removeAttribute('disabled'); radioElement.removeAttribute('disabled');

View file

@ -94,8 +94,10 @@ class formcreate
} else { } else {
// reverting to chan-sccp default values // reverting to chan-sccp default values
echo " data-for={$res_id}"; echo " data-for={$res_id}";
echo " data-type=text";
echo " class=sccp-restore"; echo " class=sccp-restore";
echo " id=usedefault_{$res_id}"; echo " id=usedefault_{$res_id}";
echo " data-default={$sccp_defaults[$res_n]['systemdefault']}";
echo " "; echo " ";
} }
?> ?>