From b468e1416dac79934815e42ec1b44a5de0d41ed8 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Mon, 5 Nov 2018 16:44:20 +0100 Subject: 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 --- modules/luci-base/htdocs/luci-static/resources/cbi.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'modules/luci-base') diff --git a/modules/luci-base/htdocs/luci-static/resources/cbi.js b/modules/luci-base/htdocs/luci-static/resources/cbi.js index 5a095bdfde..9b391c7827 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); -- cgit v1.2.3