From 4cca2c6e4b8e403632e8e47bd3b22afa2605eac1 Mon Sep 17 00:00:00 2001 From: Paul Donald Date: Fri, 25 Apr 2025 17:17:51 +0200 Subject: [PATCH] luci-base: override the load() function to return boolean for FlagValue In the underlying uci system, all variables are effectively strings, so for those configuration values which serve as 'boolean' flags, we need to coerce the various forms into a real boolean. Only the following string values result in true: 1|on|true|yes|enabled. Otherwise, false. Checkboxes now fill correctly. "Unchanged" configurations may write changed values as the Flag values are coerced to '1' or '0' on write, but the configuration behaviour remains synonymous. Signed-off-by: Paul Donald (cherry picked from commit 1355a6fa253d765140f5571354939d2e93e6d967) --- .../luci-base/htdocs/luci-static/resources/form.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/modules/luci-base/htdocs/luci-static/resources/form.js b/modules/luci-base/htdocs/luci-static/resources/form.js index 13ca76450e..db3da638a3 100644 --- a/modules/luci-base/htdocs/luci-static/resources/form.js +++ b/modules/luci-base/htdocs/luci-static/resources/form.js @@ -4000,6 +4000,19 @@ var CBIFlagValue = CBIValue.extend(/** @lends LuCI.form.FlagValue.prototype */ { * @default 'ℹ️'; */ + /** + * Coerce the various forms of a 'boolean' string into a true/false value. + * + * @override + */ + load() { + // + let load = this.super('load', arguments); + if (typeof(load) == 'string') + load = ['1', 'on', 'true', 'yes', 'enabled'].includes(load.toLowerCase()); + return load; + }, + /** @private */ renderWidget: function(section_id, option_index, cfgvalue) { var tooltip = null; -- 2.30.2