luci-base: do not coerce objects to strings
authorPaul Donald <newtwen+github@gmail.com>
Sat, 31 Jan 2026 22:49:13 +0000 (23:49 +0100)
committerPaul Donald <newtwen+github@gmail.com>
Sat, 31 Jan 2026 22:49:13 +0000 (23:49 +0100)
When getting values from the form, especially in a JSONMap,
some objects may be nested, and as such, it's not much use
to return '[object Object]'. Return the object instead, so
the caller can do something useful with it. This makes
multidimensional maps much easier to use.

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
modules/luci-base/htdocs/luci-static/resources/form.js

index c6e84e94e4bc62e7133747f8a7e14a0fc3cf87df..b5c0ea80a77c94478e7cc636731fc4ec1875605d 100644 (file)
@@ -105,6 +105,9 @@ const CBIJSONConfig = baseclass.extend({
                if (Array.isArray(value))
                        return value;
 
+               if (L.isObject(value))
+                       return value;
+
                if (value != null)
                        return String(value);
 
@@ -122,6 +125,8 @@ const CBIJSONConfig = baseclass.extend({
                        delete this.data[section][option];
                else if (Array.isArray(value))
                        this.data[section][option] = value;
+               else if (L.isObject(value))
+                       this.data[section][option] = value;
                else
                        this.data[section][option] = String(value);
        },