Skip to content

Commit

Permalink
Fixes for saving radio button preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
lkarlslund committed Dec 17, 2024
1 parent 0e73de1 commit affc912
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion modules/frontend/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@
<input type="radio" class="btn-check" name="theme" value="light" id="theme-light" preference="theme" autocomplete="off">
<label class="btn" for="theme-light">Light</label>

<input type="radio" class="btn-check" name="theme" value="auto" id="theme-auto" preference="theme" defaultpref="true" autocomplete="off">
<input type="radio" class="btn-check" name="theme" value="auto" id="theme-auto" preference="theme" defaultpref="auto" autocomplete="off">
<label class="btn" for="theme-auto">Auto</label>

<input type="radio" class="btn-check" name="theme" value="dark" id="theme-dark" preference="theme" autocomplete="off">
Expand Down
21 changes: 19 additions & 2 deletions modules/frontend/html/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,38 @@ function loadprefs() {
}

function updatecontrol(ele) {
val = getpref(ele.attr("preference"), ele.data("defaultpref"))
defaultval = $('input[name="'+ele.attr("name")+'"][defaultpref]').attr("defaultpref");
val = getpref(ele.attr("preference"), defaultval);
console.log(
"Loaded settings for " +
ele.attr("preference") +
" with default value " +
defaultval + " value " + val
);
if (val != null) {
if (ele.attr("type") == "checkbox") {
ele.prop("checked", val)
} else if (ele.attr("type") == "radio") {
ele.prop("checked", ele.val() == val)
$('[type=radio][name="'+ele.attr("name")+'"]').each(function (index, radioitem) {
console.log(radioitem);
$(this).prop("checked", $(this).attr("value") == val);
});
} else {
ele.val(val)
}
console.log("Triggering change event for element with preference "+ele.attr("preference")+" with value "+val);
ele.trigger("change");
}
}

function onchangepreference(ele) {
if (ele.attr("type") == "checkbox") {
setpref(ele.attr("preference"), ele.prop("checked"))
} else if (ele.attr("type") == "radio") {
$('input[name="'+ele.attr("name")+'"]:checked').each(function( index, checkedele ) {
console.log("Updating radio to "+$(this).val());
setpref(ele.attr("preference"), $(this).val());
});
} else {
setpref(ele.attr("preference"), ele.val())
}
Expand Down

0 comments on commit affc912

Please sign in to comment.