diff options
author | Jo-Philipp Wich <jo@mein.io> | 2019-12-30 14:40:57 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2019-12-30 14:51:40 +0100 |
commit | 9e259174323a406b93664e307bb8a50fc3d80483 (patch) | |
tree | adc140607d10b8e8e72426009b8d77e08d4dee6e /modules | |
parent | b0836b037e55bfc9201e60a9446f2f7800d7f195 (diff) |
luci-base: form.js: implement AbstractValue.getUIElement()
Introduce a new method `getUIElement()` which simplifies obtaining the
underlying per-section UI widget class instance for a from option object.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/luci-base/htdocs/luci-static/resources/form.js | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/form.js b/modules/luci-base/htdocs/luci-static/resources/form.js index 1c6f843041..180cd61a6d 100644 --- a/modules/luci-base/htdocs/luci-static/resources/form.js +++ b/modules/luci-base/htdocs/luci-static/resources/form.js @@ -765,6 +765,12 @@ var CBIAbstractValue = CBINode.extend({ this.ucioption || this.option); }, + getUIElement: function(section_id) { + var node = this.map.findElement('id', this.cbid(section_id)), + inst = node ? L.dom.findClassInstance(node) : null; + return (inst instanceof ui.AbstractElement) ? inst : null; + }, + cfgvalue: function(section_id, set_value) { if (section_id == null) L.error('TypeError', 'Section ID required'); @@ -778,8 +784,8 @@ var CBIAbstractValue = CBINode.extend({ }, formvalue: function(section_id) { - var node = this.map.findElement('id', this.cbid(section_id)); - return node ? L.dom.callClassMethod(node, 'getValue') : null; + var elem = this.getUIElement(section_id); + return elem ? elem.getValue() : null; }, textvalue: function(section_id) { @@ -796,8 +802,8 @@ var CBIAbstractValue = CBINode.extend({ }, isValid: function(section_id) { - var node = this.map.findElement('id', this.cbid(section_id)); - return node ? L.dom.callClassMethod(node, 'isValid') : true; + var elem = this.getUIElement(section_id); + return elem ? elem.isValid() : true; }, isActive: function(section_id) { @@ -817,8 +823,8 @@ var CBIAbstractValue = CBINode.extend({ }, triggerValidation: function(section_id) { - var node = this.map.findElement('id', this.cbid(section_id)); - return node ? L.dom.callClassMethod(node, 'triggerValidation') : true; + var elem = this.getUIElement(section_id); + return elem ? elem.triggerValidation() : true; }, parse: function(section_id) { @@ -1742,9 +1748,8 @@ var CBIFlagValue = CBIValue.extend({ }, formvalue: function(section_id) { - var node = this.map.findElement('id', this.cbid(section_id)), - checked = node ? L.dom.callClassMethod(node, 'isChecked') : false; - + var elem = this.getUIElement(section_id), + checked = elem ? elem.isChecked() : false; return checked ? this.enabled : this.disabled; }, |