refactored dependant field check
This commit is contained in:
@ -98,17 +98,22 @@ class ValidationField {
|
|||||||
|
|
||||||
// dependant fields
|
// dependant fields
|
||||||
if (this.dependant) {
|
if (this.dependant) {
|
||||||
const parent = this.validationInstance.form.querySelector(`[name=${this.dependant}]`)
|
const parents = this.validationInstance.form.querySelectorAll(`[name="${this.dependant}"]`)
|
||||||
|
|
||||||
const depCheck = () => {
|
const depCheck = () => {
|
||||||
parent.value
|
if (((parents[0].type === 'checkbox' || parents[0].type === 'radio') && this.validationInstance.form.querySelectorAll(`[name="${this.dependant}"]:checked`).length > 0) ||
|
||||||
? this.el.removeAttribute('disabled')
|
(((parents[0].type !== 'checkbox' && parents[0].type !== 'radio') && parents[0].value))) {
|
||||||
: this.el.setAttribute('disabled', 'disabled')
|
this.el.removeAttribute('disabled')
|
||||||
|
} else {
|
||||||
|
this.el.setAttribute('disabled', 'disabled')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
depCheck()
|
depCheck()
|
||||||
|
|
||||||
|
for (const parent of parents) {
|
||||||
parent.addEventListener('input', depCheck)
|
parent.addEventListener('input', depCheck)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// add required indicator
|
// add required indicator
|
||||||
if (this.validationInstance.reqIndicators) {
|
if (this.validationInstance.reqIndicators) {
|
||||||
|
Reference in New Issue
Block a user