added dependant fields; fixed disabled fields getting a required indicator on page load
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
class ValidationField {
|
||||
dependant = null
|
||||
el = null
|
||||
formGroupEl = null
|
||||
isValid = null
|
||||
@ -95,10 +96,24 @@ class ValidationField {
|
||||
// add a native pattern attr if pattern property is present
|
||||
if (this.pattern) this.el.setAttribute('pattern', this.pattern)
|
||||
|
||||
// dependant fields
|
||||
if (this.dependant) {
|
||||
const parent = this.validationInstance.form.querySelector(`[name=${this.dependant}]`)
|
||||
|
||||
const depCheck = () => {
|
||||
parent.value
|
||||
? this.el.removeAttribute('disabled')
|
||||
: this.el.setAttribute('disabled', 'disabled')
|
||||
}
|
||||
depCheck()
|
||||
|
||||
parent.addEventListener('input', depCheck)
|
||||
}
|
||||
|
||||
// add required indicator
|
||||
if (this.validationInstance.reqIndicators) {
|
||||
const hasIndicator = this.formGroupEl?.querySelector(`.${this.validationInstance.reqIndicatorClass}`)
|
||||
if (!hasIndicator && !this.optional) {
|
||||
if (!hasIndicator && !this.optional && !this.el.disabled) {
|
||||
this.labelEl?.insertAdjacentHTML(
|
||||
'beforeend',
|
||||
`<span class="${this.validationInstance.reqIndicatorClass}">${this.validationInstance.reqIndicator}</span>`
|
||||
|
Reference in New Issue
Block a user