summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2018-11-05 16:44:20 +0100
committerJo-Philipp Wich <jo@mein.io>2018-11-14 20:46:04 +0100
commitb468e1416dac79934815e42ec1b44a5de0d41ed8 (patch)
tree7784b289d472cdefb9a9d2f9e481b6393e65fc61
parenta453f2b9d0eb4345513ac9f493e5bd88337ac244 (diff)
luci-base: cbi.js: avoid using .form property directly
In order to prepare support for calling cbi validation on non-native form widgets, remove direct usages of the node.form property and lookup the containing form using findParent() instead. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r--modules/luci-base/htdocs/luci-static/resources/cbi.js10
1 files changed, 6 insertions, 4 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/cbi.js b/modules/luci-base/htdocs/luci-static/resources/cbi.js
index 5a095bdfd..9b391c782 100644
--- a/modules/luci-base/htdocs/luci-static/resources/cbi.js
+++ b/modules/luci-base/htdocs/luci-static/resources/cbi.js
@@ -228,7 +228,7 @@ var CBIValidatorPrototype = {
validate: function() {
/* element is detached */
- if (!this.field.form)
+ if (!findParent(this.field, 'form'))
return true;
this.field.classList.remove('cbi-input-invalid');
@@ -1124,10 +1124,12 @@ function cbi_validate_field(cbid, optional, type)
};
if (validatorFn !== null) {
- if (!field.form.cbi_validators)
- field.form.cbi_validators = [ ];
+ var form = findParent(field, 'form');
- field.form.cbi_validators.push(validatorFn);
+ if (!form.cbi_validators)
+ form.cbi_validators = [ ];
+
+ form.cbi_validators.push(validatorFn);
field.addEventListener("blur", validatorFn);
field.addEventListener("keyup", validatorFn);