6262</template >
6363
6464<script lang="ts">
65- import { mockAsync } from ' @/core/utils/helpers' ;
65+ import { mockAsync , mockAsyncValidator } from ' @/core/utils/helpers' ;
6666import { computed , defineComponent , onMounted , reactive , ref } from ' vue' ;
6767import {
68- FormValidation ,
69- email ,
70- pattern ,
7168 TextField ,
7269 SelectField ,
7370 EmailField ,
@@ -77,6 +74,13 @@ import {
7774 RadioField ,
7875 CustomField ,
7976 ColorField ,
77+ Validator ,
78+ FormValidator ,
79+ required ,
80+ email ,
81+ pattern ,
82+ ValidatorTrigger ,
83+ ValidationTriggerTypes ,
8084} from ' ../../src' ;
8185/* } from '../../dist/as-dynamic-forms.esm'; */
8286export default defineComponent ({
@@ -85,18 +89,28 @@ export default defineComponent({
8589 const title = ref (' Vue Dynamic Forms' );
8690 const formValues = reactive ({});
8791 let consoleOptions = ref ();
88- const emailValidator: FormValidation = {
92+ const emailValidator: FormValidator = {
8993 validator: email ,
9094 text: ' Email format is incorrect' ,
9195 };
9296
93- const passwordValidator: FormValidation = {
97+ const emailUniquenessValidator: FormValidator = {
98+ validator : value =>
99+ mockAsyncValidator (
100+ ' isUnique' ,
101+ value === ' alvaro.saburido@gmail.com' ,
102+ 2000 ,
103+ ),
104+ text: ' Email must be unique' ,
105+ };
106+
107+ const passwordValidator: FormValidator = Validator ({
94108 validator: pattern (
95109 ' ^(?=.*[a-z])(?=.*[A-Z])(?=.*)(?=.*[#$^+=!*()@%&]).{8,10}$' ,
96110 ),
97111 text:
98112 ' Password must contain at least 1 Uppercase, 1 Lowercase, 1 number, 1 special character and min 8 characters max 10' ,
99- };
113+ }) ;
100114
101115 const form = computed (() => ({
102116 id: ' example-form' ,
@@ -118,14 +132,18 @@ export default defineComponent({
118132 fields: {
119133 name: TextField ({
120134 label: ' Name' ,
121- required: true ,
135+ customClass: ' w-1/2 pr-4' ,
136+ validations: [
137+ Validator ({ validator: required , text: ' This field is required' }),
138+ ],
122139 }),
123140 email: EmailField ({
124141 label: ' Email' ,
125- validations: [emailValidator ],
142+ validations: [emailValidator , emailUniquenessValidator ],
126143 customClass: {
127144 active: true ,
128145 ' text-blue' : true ,
146+ ' w-1/2' : true ,
129147 },
130148 }),
131149 password: PasswordField ({
@@ -135,6 +153,7 @@ export default defineComponent({
135153 }),
136154 stock: NumberField ({
137155 label: ' Stock' ,
156+ customClass: ' w-1/2 pr-4' ,
138157 }),
139158 games: SelectField ({
140159 label: ' Games' ,
@@ -157,7 +176,7 @@ export default defineComponent({
157176 }),
158177 console: SelectField ({
159178 label: ' Console (Async Options)' ,
160- customClass: ' w-1/2' ,
179+ customClass: ' w-1/2 pr-4 ' ,
161180 options: consoleOptions .value ,
162181 }),
163182 steps: NumberField ({
@@ -166,6 +185,7 @@ export default defineComponent({
166185 max: 60 ,
167186 step: 5 ,
168187 value: 5 ,
188+ customClass: ' w-1/2 ' ,
169189 }),
170190 awesomeness: CheckboxField ({
171191 label: " Check if you're awesome" ,
@@ -201,10 +221,15 @@ export default defineComponent({
201221 }),
202222 customStyles: TextField ({
203223 label: ' Custom Styles' ,
204- required: true ,
205224 customStyles: {
206225 border: ' 1px solid teal' ,
207226 },
227+ validations: [emailValidator ],
228+
229+ validationTrigger: ValidatorTrigger ({
230+ type: ValidationTriggerTypes .CHANGE ,
231+ threshold: 4 ,
232+ }),
208233 }),
209234 readonly: TextField ({
210235 label: ' Readonly' ,
0 commit comments