47
47
</template >
48
48
</v-stepper-header >
49
49
50
- <v-stepper-window >
51
- <v-stepper-window-item
52
- v-for =" page, i in pages"
53
- :key =" `${i}-content`"
54
- :reverse-transition =" transition"
55
- :transition =" transition"
56
- :value =" getIndex(i)"
57
- >
58
- <v-container >
59
- <PageContainer
60
- v-if =" !page.isReview"
61
- v-model =" modelValue"
62
- :index =" getIndex(i)"
63
- :page =" page"
64
- :settings =" settings"
65
- @callback =" callbacks"
66
- @next =" validatePage(next)"
67
- />
68
- <PageReviewContainer
69
- v-else
70
- v-model =" modelValue"
71
- :page =" page"
72
- :pages =" pages"
73
- :settings =" settings"
74
- :summary-columns =" summaryColumns"
75
- @goToQuestion =" stepperModel = $event"
76
- @submit =" submitForm"
50
+ <form @submit.prevent =" onSubmit" >
51
+ <v-stepper-window >
52
+ <v-stepper-window-item
53
+ v-for =" page, i in pages"
54
+ :key =" `${i}-content`"
55
+ :reverse-transition =" transition"
56
+ :transition =" transition"
57
+ :value =" getIndex(i)"
58
+ >
59
+ <v-container >
60
+ <PageContainer
61
+ v-if =" !page.isReview"
62
+ v-model =" modelValue"
63
+ :index =" getIndex(i)"
64
+ :page =" page"
65
+ :settings =" settings"
66
+ :validateSchema =" validateSchema"
67
+ @next =" validatePage(next)"
68
+ @validate =" onSubmit"
69
+ />
70
+ <PageReviewContainer
71
+ v-else
72
+ v-model =" modelValue"
73
+ :page =" page"
74
+ :pages =" pages"
75
+ :settings =" settings"
76
+ :summary-columns =" summaryColumns"
77
+ @goToQuestion =" stepperModel = $event"
78
+ @submit =" submitForm"
79
+ />
80
+ </v-container >
81
+ </v-stepper-window-item >
82
+ </v-stepper-window >
83
+
84
+ <v-stepper-actions v-if =" !settings.hideActions" >
85
+ <template #next >
86
+ <v-btn
87
+ :color =" settings.color"
88
+ :disabled =" ((stepperActionsDisabled === 'next' || settings.disabled) as boolean)"
89
+ :size =" navButtonSize"
90
+ @click =" validatePage(next)"
77
91
/>
78
- </v-container >
79
- </v-stepper-window-item >
80
- </v-stepper-window >
81
-
82
- <v-stepper-actions v-if =" !settings.hideActions" >
83
- <template #next >
84
- <v-btn
85
- :color =" settings.color"
86
- :disabled =" ((stepperActionsDisabled === 'next' || settings.disabled) as boolean)"
87
- :size =" navButtonSize"
88
- @click =" validatePage(next)"
89
- />
90
- </template >
92
+ </template >
91
93
92
- <template #prev >
93
- <v-btn
94
- :disabled =" ((stepperActionsDisabled === 'prev' || settings.disabled || canReviewPreviousButtonDisabled) as boolean)"
95
- :size =" navButtonSize"
96
- @click =" previousPage(prev)"
97
- />
98
- </template >
99
- </v-stepper-actions >
94
+ <template #prev >
95
+ <v-btn
96
+ :disabled =" ((stepperActionsDisabled === 'prev' || settings.disabled || canReviewPreviousButtonDisabled) as boolean)"
97
+ :size =" navButtonSize"
98
+ @click =" previousPage(prev)"
99
+ />
100
+ </template >
101
+ </v-stepper-actions >
102
+
103
+ <v-row >
104
+ <v-col >
105
+ <v-btn type =" submit" >Submit</v-btn >
106
+ </v-col >
107
+ </v-row >
108
+ </form >
100
109
</template >
101
110
</v-stepper >
102
111
</v-container >
@@ -127,6 +136,9 @@ import PageContainer from './components/shared/PageContainer.vue';
127
136
import PageReviewContainer from ' ./components/shared/PageReviewContainer.vue' ;
128
137
import { useMergeProps } from ' ./composables/helpers' ;
129
138
import { watchDeep } from ' @vueuse/core' ;
139
+ import {
140
+ useGetValidationSchema ,
141
+ } from ' ./composables/validation' ;
130
142
131
143
132
144
const attrs = useAttrs ();
@@ -178,6 +190,59 @@ const settings = ref<Settings>({
178
190
console .log (' settings.value' , settings .value );
179
191
180
192
193
+ // const { handleSubmit } = useForm({
194
+ // validationSchema: toTypedSchema(
195
+ // yupObject({
196
+ // }),
197
+ // ),
198
+ // });
199
+
200
+ // const onSubmit = handleSubmit(item => {
201
+ // console.log('onSubmit handleSubmit', item);
202
+ // });
203
+
204
+ const allFieldsArray = ref <Field []>([]);
205
+
206
+ Object .values (pages .value ).forEach ((p : Page ) => {
207
+ Object .values (p .fields ).forEach ((field : Field ) => {
208
+ allFieldsArray .value .push (field as Field );
209
+ });
210
+ });
211
+
212
+ const validateSchema = useGetValidationSchema (allFieldsArray .value );
213
+ console .log (' validateSchema' , validateSchema );
214
+
215
+ // const initialValues = {};
216
+ // allFieldsArray.value.forEach(item => {
217
+ // initialValues[item.name] = item.label || "";
218
+ // });
219
+
220
+ // const yepSchema = allFieldsArray.value.reduce(useCreateYupSchema, { validationType: 'required', validations: allFieldsArray.value });
221
+ // console.log('yepSchema', yepSchema);
222
+ // const validateSchema = yupObject().shape(yepSchema);
223
+ // console.log('validateSchema', validateSchema);
224
+
225
+ // const foo = useCreateYupSchema(allFieldsArray.value, {});
226
+
227
+ // console.log(foo);
228
+
229
+ function onSubmit() {
230
+ console .log (' onSubmit' );
231
+ // useValidation({
232
+ // fields: allFieldsArray.value,
233
+ // });
234
+ }
235
+
236
+
237
+ // function validateField(field: Field) {
238
+ // console.log('validateField', field);
239
+ // console.log('allFieldsArray', allFieldsArray.value);
240
+ // useValidation({
241
+ // fields: allFieldsArray.value,
242
+ // });
243
+ // }
244
+
245
+
181
246
// const StepperComponent = markRaw(props.direction === 'vertical' ? VStepperVertical : VStepper);
182
247
// console.log('StepperComponent', StepperComponent);
183
248
@@ -186,7 +251,14 @@ console.log('settings.value', settings.value);
186
251
onMounted (() => {
187
252
whenCallback ();
188
253
254
+ // useSetupValidation({
255
+ // fields: allFieldsArray.value,
256
+ // });
257
+
189
258
summaryColumnErrorCheck ();
259
+
260
+
261
+
190
262
});
191
263
192
264
@@ -260,6 +332,8 @@ function headerItemDisabled(page: Page): boolean {
260
332
261
333
262
334
// ------------------------------------------------ Callback & Validation //
335
+
336
+
263
337
// const pagesValidation = ref((pages.value)
264
338
// .map((_, i) => ({ page: i + 1, valid: false })));
265
339
@@ -280,9 +354,7 @@ function callbacks() {
280
354
}
281
355
282
356
283
-
284
-
285
-
357
+ // ------------------------ Conditional "when" callback //
286
358
function whenCallback() {
287
359
Object .values (pages .value ).forEach ((page : Page , pageIdx : number ) => {
288
360
Object .values (page .fields as Field []).forEach ((field : Field , fieldIdx ) => {
0 commit comments