FIX: form/field validation extra checks repeated funcs

This commit is contained in:
Tony Air 2024-06-26 03:43:08 +02:00
parent 2fc7882cf7
commit 52cade10c8
2 changed files with 8 additions and 16 deletions

View File

@ -3,7 +3,7 @@ const NAME = 'ui.validate.field'
class ValidateField {
#field
#extraChecks = []
#extraChecks = {}
constructor(field) {
this.#field = field
@ -26,10 +26,7 @@ class ValidateField {
}
addExtraCheck = (validateFunc) => {
if (!this.#extraChecks.includes(validateFunc)) {
this.#extraChecks.push(validateFunc)
}
this.#extraChecks[validateFunc.name] = validateFunc
return this
}
@ -43,10 +40,8 @@ class ValidateField {
// run extra checks
let valid = true
console.log(this.#extraChecks)
for (const validateFunc of this.#extraChecks) {
valid = validateFunc(this.#field)
for (const validateFuncName in this.#extraChecks) {
valid = this.#extraChecks[validateFuncName](this.#field)
if (!valid) {
break

View File

@ -6,7 +6,7 @@ const NAME = 'ui.validate.form'
class ValidateForm {
#steppedUI
#form
#extraChecks = []
#extraChecks = {}
constructor(form) {
this.#form = form
@ -61,10 +61,7 @@ class ValidateForm {
}
addExtraCheck = (validateFunc) => {
if (!this.#extraChecks.includes(validateFunc)) {
this.#extraChecks.push(validateFunc)
}
this.#extraChecks[validateFunc.name] = validateFunc
return this
}
@ -87,8 +84,8 @@ class ValidateForm {
}
// run extra checks
for (const validateFunc of this.#extraChecks) {
valid = validateFunc(this.#form)
for (const validateFuncName in this.#extraChecks) {
valid = this.#extraChecks[validateFuncName](this.#form)
if (!valid) {
break