summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2020-08-06 16:56:46 +0200
committerJo-Philipp Wich <jo@mein.io>2020-08-06 17:56:34 +0200
commit35e2735e2ebc5cee82bcb746b86ca417e9fe4088 (patch)
treefea6e0306f83534abec0fb07b174fa7340978824 /modules/luci-base
parent18eddc962418a045524a740061625834a77153d8 (diff)
luci-base: form.js: implement AbstractSection.getOption() helper
The `getOption()` function allows to easily obtain a reference to another option object instance within the same section. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-base')
-rw-r--r--modules/luci-base/htdocs/luci-static/resources/form.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/form.js b/modules/luci-base/htdocs/luci-static/resources/form.js
index 32d803d6a..568a4abb6 100644
--- a/modules/luci-base/htdocs/luci-static/resources/form.js
+++ b/modules/luci-base/htdocs/luci-static/resources/form.js
@@ -1156,6 +1156,36 @@ var CBIAbstractSection = CBIAbstractElement.extend(/** @lends LuCI.form.Abstract
return rv;
},
+ /**
+ * Obtain underlying option objects.
+ *
+ * This function is sensitive to the amount of arguments passed to it;
+ * if no option name is specified, all options within this section are
+ * returned as dictionary.
+ *
+ * If an option name is supplied, this function returns the matching
+ * LuCI.form.AbstractValue instance only.
+ *
+ * @param {string} [option]
+ * The name of the option object to obtain
+ *
+ * @returns {null|LuCI.form.AbstractValue|Object<string, LuCI.form.AbstractValue>}
+ * Returns either a dictionary of option names and their corresponding
+ * option instance objects or just a single object instance value,
+ * depending on the amount of passed arguments.
+ */
+ getOption: function(option) {
+ var rv = (arguments.length == 0) ? {} : null;
+
+ for (var i = 0, o; (o = this.children[i]) != null; i++)
+ if (rv)
+ rv[o.option] = o;
+ else if (o.option == option)
+ return o;
+
+ return rv;
+ },
+
/** @private */
renderUCISection: function(section_id) {
var renderTasks = [];