This repository was archived by the owner on Jun 27, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +22
-7
lines changed Expand file tree Collapse file tree 4 files changed +22
-7
lines changed Original file line number Diff line number Diff line change @@ -150,6 +150,7 @@ const data = () => ({
150
150
}),
151
151
],
152
152
options: {
153
+ // autoValidate: true,
153
154
customClass: ' row' ,
154
155
netlify: true ,
155
156
},
Original file line number Diff line number Diff line change @@ -71,15 +71,25 @@ const watch = {
71
71
} ;
72
72
73
73
const computed = {
74
+ getClasses ( ) {
75
+ return [
76
+ 'dynamic-input' ,
77
+ 'form-group' ,
78
+ {
79
+ 'form-group--error' : this . showErrors ,
80
+ } ,
81
+ `${ this . formControl . customClass || '' } ` ,
82
+ ] ;
83
+ } ,
74
84
hasValue ( ) {
75
85
const { value } = this . formControl ;
76
86
return value !== null && value !== undefined ;
77
87
} ,
78
- hasErrors ( ) {
88
+ showErrors ( ) {
79
89
return (
80
90
this . formControl . errors &&
81
91
Object . keys ( this . formControl . errors ) . length > 0 &&
82
- this . submited
92
+ ( this . submited || this . autoValidate )
83
93
) ;
84
94
} ,
85
95
errorMessages ( ) {
@@ -92,6 +102,11 @@ const computed = {
92
102
submited ( ) {
93
103
return this . $parent . submited ;
94
104
} ,
105
+ autoValidate ( ) {
106
+ return (
107
+ this . $parent . options . autoValidate && this . formControl . touched === true
108
+ ) ;
109
+ } ,
95
110
} ;
96
111
97
112
const DynamicInput = {
Original file line number Diff line number Diff line change 1
1
<template >
2
- <div
3
- class =" dynamic-input form-group"
4
- :class =" ({ 'form-group--error': hasErrors }, `${formControl.customClass || ''}`)"
5
- >
2
+ <div :class =" getClasses" >
6
3
<label
7
4
class =" form-label"
8
5
:for =" formControl.name"
47
44
:onFocus =" onFocus"
48
45
:onBlur =" onBlur"
49
46
/>
50
- <div v-if =" hasErrors " >
47
+ <div v-if =" showErrors " >
51
48
<p
52
49
v-for =" (errorText, $index) in errorMessages"
53
50
:key =" `${$index}`"
Original file line number Diff line number Diff line change @@ -61,11 +61,13 @@ export function FormValidation(
61
61
export function FormOptions ( {
62
62
customClass = '' ,
63
63
method = 'POST' ,
64
+ autoValidate = false ,
64
65
netlify = false ,
65
66
netlifyHoneypot = null ,
66
67
} ) {
67
68
this . customClass = customClass ;
68
69
this . method = method ;
70
+ this . autoValidate = autoValidate ;
69
71
this . netlify = netlify ;
70
72
this . netlifyHoneypot = netlifyHoneypot ;
71
73
}
You can’t perform that action at this time.
0 commit comments