fixed optional fields not validating while having a value
This commit is contained in:
@ -263,41 +263,41 @@ class Validation {
|
||||
parseField(fieldInstance) {
|
||||
const nameAttrVal = fieldInstance.el.name
|
||||
|
||||
if (!fieldInstance.optional) {
|
||||
if (!fieldInstance.el.value) {
|
||||
this.validateForBlank(fieldInstance)
|
||||
this.validateForBlank(fieldInstance)
|
||||
|
||||
if (fieldInstance.el.value) {
|
||||
if (fieldInstance.pattern) {
|
||||
this.validatePattern(fieldInstance)
|
||||
} else {
|
||||
if (fieldInstance.pattern) {
|
||||
this.validatePattern(fieldInstance)
|
||||
} else {
|
||||
switch (fieldInstance.el.type) {
|
||||
case 'checkbox':
|
||||
this.validateCheckbox(fieldInstance, nameAttrVal)
|
||||
break
|
||||
case 'email':
|
||||
this.validateEmail(fieldInstance)
|
||||
break
|
||||
case 'password':
|
||||
if (fieldInstance.el.name === 'password') this.validatePassword(fieldInstance)
|
||||
if (fieldInstance.el.name === 'password-confirm') this.validateConfirmPass(fieldInstance)
|
||||
break
|
||||
case 'radio':
|
||||
this.validateRadio(fieldInstance, nameAttrVal)
|
||||
break
|
||||
case 'tel':
|
||||
this.validateTel(fieldInstance)
|
||||
break
|
||||
}
|
||||
switch (fieldInstance.el.type) {
|
||||
case 'checkbox':
|
||||
this.validateCheckbox(fieldInstance, nameAttrVal)
|
||||
break
|
||||
case 'email':
|
||||
this.validateEmail(fieldInstance)
|
||||
break
|
||||
case 'password':
|
||||
if (fieldInstance.el.name === 'password') this.validatePassword(fieldInstance)
|
||||
if (fieldInstance.el.name === 'password-confirm') this.validateConfirmPass(fieldInstance)
|
||||
break
|
||||
case 'radio':
|
||||
this.validateRadio(fieldInstance, nameAttrVal)
|
||||
break
|
||||
case 'tel':
|
||||
this.validateTel(fieldInstance)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
validateForBlank(fieldInstance) {
|
||||
this.addError(
|
||||
fieldInstance,
|
||||
(fieldInstance.labelText ? fieldInstance.labelText : `Field`) + ` is required.`
|
||||
)
|
||||
if (!fieldInstance.el.value && !fieldInstance.optional) {
|
||||
this.addError(
|
||||
fieldInstance,
|
||||
(fieldInstance.labelText ? fieldInstance.labelText : `Field`) + ` is required.`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
validatePattern(fieldInstance) {
|
||||
|
Reference in New Issue
Block a user