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:
parent
a453f2b9d0
commit
b468e1416d
1 changed files with 6 additions and 4 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue