luci-base: cbi.js: avoid using .form property directly
authorJo-Philipp Wich <jo@mein.io>
Mon, 5 Nov 2018 15:44:20 +0000 (16:44 +0100)
committerJo-Philipp Wich <jo@mein.io>
Wed, 14 Nov 2018 19:46:04 +0000 (20:46 +0100)
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>
modules/luci-base/htdocs/luci-static/resources/cbi.js

index 5a095bdfde22f89687ec98bd686d5783ba74141c..9b391c7827c8df3f19b5bbb500c0aa8bf0fd11a4 100644 (file)
@@ -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);