Skip to content

Commit 42ce3d9

Browse files
[DEV] * add settings fieldColumns prop
* add field.columns prop * move column error checking into composable * testing and fixing props
1 parent 716bc34 commit 42ce3d9

File tree

29 files changed

+703
-1290
lines changed

29 files changed

+703
-1290
lines changed

src/playground/configs/templates/PlaygroundPage.vue

Lines changed: 387 additions & 439 deletions
Large diffs are not rendered by default.

src/plugin/VStepperForm.vue

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
<Form
6060
ref="stepperFormRef"
6161
v-slot="{ validate }"
62-
:validation-schema="validateSchema"
62+
:validate-on-mount="settings?.validateOnMount"
63+
:validation-schema="validationSchema"
6364
@submit="onSubmit"
6465
>
6566
<v-stepper-window>
@@ -75,6 +76,7 @@
7576
v-if="!page.isReview"
7677
:key="`${getIndex(i)}-page`"
7778
v-model="modelValue"
79+
:fieldColumns="settings?.fieldColumns"
7880
:index="getIndex(i)"
7981
:page="page"
8082
:settings="settings"
@@ -146,7 +148,6 @@
146148
</template>
147149

148150
<script setup lang="ts">
149-
// TODO: Conditionals needs to update the validation //
150151
// import { VStepper } from 'vuetify/components';
151152
// import { VStepperVertical } from 'vuetify/labs/VStepperVertical';
152153
import { AllProps } from './utils/props';
@@ -159,7 +160,6 @@ import type {
159160
Page,
160161
Props,
161162
Settings,
162-
SummaryColumns,
163163
} from '@/plugin/types';
164164
import {
165165
useContainerClasses,
@@ -170,7 +170,10 @@ import { globalOptions } from './';
170170
import { toTypedSchema } from '@vee-validate/yup';
171171
import PageContainer from './components/shared/PageContainer.vue';
172172
import PageReviewContainer from './components/shared/PageReviewContainer.vue';
173-
import { useMergeProps } from './composables/helpers';
173+
import {
174+
useColumnErrorCheck,
175+
useMergeProps,
176+
} from './composables/helpers';
174177
import { watchDeep } from '@vueuse/core';
175178
176179
@@ -201,6 +204,7 @@ const settings = ref<Settings>({
201204
editable: stepperProps.editable,
202205
elevation: stepperProps.elevation,
203206
errorIcon: stepperProps.errorIcon,
207+
fieldColumns: stepperProps.fieldColumns,
204208
flat: stepperProps.flat,
205209
height: stepperProps.height,
206210
hideActions: stepperProps.hideActions,
@@ -217,6 +221,7 @@ const settings = ref<Settings>({
217221
tile: stepperProps.tile,
218222
transition: stepperProps.transition,
219223
validateOn: stepperProps.validateOn,
224+
validateOnMount: stepperProps.validateOnMount,
220225
variant: stepperProps.variant,
221226
});
222227
@@ -237,7 +242,16 @@ Object.values(pages).forEach((p: Page) => {
237242
// -------------------------------------------------- Mounted //
238243
onMounted(() => {
239244
whenCallback();
240-
summaryColumnErrorCheck();
245+
246+
useColumnErrorCheck({
247+
columns: props.fieldColumns,
248+
propName: '"fieldColumns"',
249+
});
250+
251+
useColumnErrorCheck({
252+
columns: props.summaryColumns,
253+
propName: '"summaryColumns"',
254+
});
241255
});
242256
243257
@@ -307,7 +321,7 @@ function headerItemDisabled(page: Page): boolean {
307321
308322
309323
// & ------------------------------------------------ Validation //
310-
const validateSchema = computed(() => toTypedSchema(props.schema as Props['schema']));
324+
const validationSchema = computed(() => toTypedSchema(props.validationSchema as Props['validationSchema']));
311325
const fieldsHaveErrors = ref(false);
312326
const currentPageHasErrors = ref(false);
313327
const errorPageIndexes = ref<number[]>([]);
@@ -386,6 +400,7 @@ function onFieldValidate(field: Field, next: () => void): void {
386400
const shouldAutoPage = (field.autoPage || settings.value.autoPage ? next : null) as () => void;
387401
388402
// ! Auto page not working //
403+
// TODO: Add debouncing //
389404
390405
checkForPageErrors(errors, 'field', shouldAutoPage);
391406
}
@@ -452,28 +467,6 @@ const formContainerStyle = computed<CSSProperties>(() => {
452467
function getIndex(i: number): number {
453468
return i + 1;
454469
}
455-
456-
457-
// ------------------------------------------------ Error Checking //
458-
function summaryColumnErrorCheck(): void {
459-
let err = false;
460-
461-
if (!props.summaryColumns) {
462-
return;
463-
}
464-
465-
Object.values(props.summaryColumns as SummaryColumns).forEach((column) => {
466-
if (column < 1 || column > 12) {
467-
err = true;
468-
}
469-
});
470-
471-
if (!err) {
472-
return;
473-
}
474-
475-
throw new Error('Summary column values must be between 1 and 12');
476-
}
477470
</script>
478471

479472
<style lang="scss" scoped>

src/plugin/components/fields/CommonField/CommonField.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
v-slot="{ errorMessage, validate }"
44
v-model="modelValue"
55
:name="field.name"
6+
:validate-on-blur="fieldValidateOn === 'blur'"
7+
:validate-on-change="fieldValidateOn === 'change'"
8+
:validate-on-input="fieldValidateOn === 'input'"
69
:validate-on-model-update="false"
710
>
811
<component
@@ -24,8 +27,6 @@
2427
</template>
2528
</component>
2629
</Field>
27-
28-
<!-- Vuetify Field {{ field }} -->
2930
</template>
3031

3132

@@ -48,6 +49,7 @@ const fieldRequired = computed(() => {
4849
const hasRequiredRule = field.rules?.find((rule) => rule.type === 'required');
4950
return field.required || hasRequiredRule as FieldLabelProps['required'];
5051
});
52+
const fieldValidateOn = computed(() => field?.validateOn ?? settings?.validateOn);
5153
5254
5355
// ------------------------- Validate On Actions //

src/plugin/components/fields/VSFAutocomplete/VSFAutocomplete.vue

Lines changed: 0 additions & 74 deletions
This file was deleted.

src/plugin/components/fields/VSFAutocomplete/index.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/plugin/components/fields/VSFCheckbox/VSFCheckbox.vue

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
v-slot="{ errorMessage, validate }"
55
v-model="modelValue"
66
:name="field.name"
7+
:validate-on-blur="fieldValidateOn === 'blur'"
8+
:validate-on-change="fieldValidateOn === 'change'"
9+
:validate-on-input="fieldValidateOn === 'input'"
710
:validate-on-model-update="false"
811
>
912
<v-checkbox
@@ -55,27 +58,36 @@
5558
:style="checkboxContainerStyle"
5659
>
5760
<Field
58-
v-for="option in field?.options"
59-
:key="option.value"
6061
v-slot="{ errorMessage, validate }"
6162
v-model="modelValue"
6263
:name="field.name"
64+
:validate-on-blur="fieldValidateOn === 'blur'"
65+
:validate-on-change="fieldValidateOn === 'change'"
66+
:validate-on-input="fieldValidateOn === 'input'"
6367
:validate-on-model-update="false"
6468
>
65-
<v-checkbox
66-
v-bind="boundSettings"
67-
:id="option.id"
68-
v-model="modelValue"
69-
:error="errorMessage ? errorMessage?.length > 0 : false"
70-
:error-messages="errorMessage"
71-
:label="option.label"
72-
:style="checkboxStyle"
73-
:true-value="option.value"
74-
@blur="onActions(validate, 'blur')"
75-
@change="onActions(validate, 'change')"
76-
@input="onActions(validate, 'input')"
69+
<template
70+
v-for="option, key in field?.options"
71+
:key="option.value"
7772
>
78-
</v-checkbox>
73+
<v-checkbox
74+
v-bind="boundSettings"
75+
:id="option.id"
76+
v-model="modelValue"
77+
:error="errorMessage ? errorMessage?.length > 0 : false"
78+
:error-messages="errorMessage"
79+
:label="option.label"
80+
:style="checkboxStyle"
81+
:true-value="option.value"
82+
@blur="onActions(validate, 'blur')"
83+
@change="onActions(validate, 'change')"
84+
@input="onActions(validate, 'input')"
85+
>
86+
<template #message>
87+
{{ Object.keys(field?.options as KeyStringAny).length - 1 === key ? errorMessage : '' }}
88+
</template>
89+
</v-checkbox>
90+
</template>
7991
</Field>
8092
</div>
8193
</div>
@@ -102,6 +114,7 @@ const fieldRequired = computed(() => {
102114
const hasRequiredRule = field.rules?.find((rule) => rule.type === 'required');
103115
return field.required || hasRequiredRule as FieldLabelProps['required'];
104116
});
117+
const fieldValidateOn = computed(() => field?.validateOn ?? settings?.validateOn);
105118
106119
107120
// ------------------------- Validate On Actions //

0 commit comments

Comments
 (0)