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>
This commit is contained in:
Jo-Philipp Wich 2018-11-05 16:44:20 +01:00
parent a453f2b9d0
commit b468e1416d

View 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);