mirror of
https://github.com/a2nt/webpack-bootstrap-ui-kit.git
synced 2024-10-22 11:05:45 +02:00
IMPR: Add validate form/field functionality
This commit is contained in:
parent
8f55fa6ef4
commit
2fc7882cf7
@ -25,8 +25,12 @@ class ValidateField {
|
|||||||
this.#field.dispatchEvent(new Event(Events.FORM_INIT_VALIDATE_FIELD))
|
this.#field.dispatchEvent(new Event(Events.FORM_INIT_VALIDATE_FIELD))
|
||||||
}
|
}
|
||||||
|
|
||||||
addExtraCheck = (func) => {
|
addExtraCheck = (validateFunc) => {
|
||||||
this.#extraChecks.push(func)
|
if (!this.#extraChecks.includes(validateFunc)) {
|
||||||
|
this.#extraChecks.push(validateFunc)
|
||||||
|
}
|
||||||
|
|
||||||
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
validate = () => {
|
validate = () => {
|
||||||
@ -39,8 +43,10 @@ class ValidateField {
|
|||||||
|
|
||||||
// run extra checks
|
// run extra checks
|
||||||
let valid = true
|
let valid = true
|
||||||
for (const func in this.#extraChecks) {
|
console.log(this.#extraChecks)
|
||||||
valid = func(this.#field)
|
|
||||||
|
for (const validateFunc of this.#extraChecks) {
|
||||||
|
valid = validateFunc(this.#field)
|
||||||
|
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
break
|
break
|
||||||
|
@ -60,8 +60,12 @@ class ValidateForm {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addExtraCheck = (func) => {
|
addExtraCheck = (validateFunc) => {
|
||||||
this.#extraChecks.push(func)
|
if (!this.#extraChecks.includes(validateFunc)) {
|
||||||
|
this.#extraChecks.push(validateFunc)
|
||||||
|
}
|
||||||
|
|
||||||
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
validate = async () => {
|
validate = async () => {
|
||||||
@ -83,8 +87,8 @@ class ValidateForm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// run extra checks
|
// run extra checks
|
||||||
for (const func in this.#extraChecks) {
|
for (const validateFunc of this.#extraChecks) {
|
||||||
valid = func(this.#form)
|
valid = validateFunc(this.#form)
|
||||||
|
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
break
|
break
|
||||||
|
Loading…
Reference in New Issue
Block a user