@ederzeel/nuxt-schema-form-nightly 0.1.0-29032620.c5a2b0b → 0.1.0-29038426.cbfab60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3,8 +3,12 @@ import SComponent from './SComponent.vue'
|
|
|
3
3
|
import convertToYup from 'json-schema-yup-transformer'
|
|
4
4
|
import type { JsonSchema } from 'json-schema-library'
|
|
5
5
|
import { computed, ref } from 'vue'
|
|
6
|
+
import type { Config } from 'json-schema-yup-transformer'
|
|
6
7
|
|
|
7
|
-
const props = defineProps<{
|
|
8
|
+
const props = defineProps<{
|
|
9
|
+
schema: JsonSchema
|
|
10
|
+
options?: { customValidation?: CustomValidation[]; jsonSchemaYupTransfromer?: Config }
|
|
11
|
+
}>()
|
|
8
12
|
|
|
9
13
|
const value = defineModel<Record<string, unknown>>({ required: true })
|
|
10
14
|
const formRef = ref()
|
|
@@ -15,7 +19,8 @@ async function onSubmit(_event: unknown) {
|
|
|
15
19
|
emit('submit', value.value)
|
|
16
20
|
}
|
|
17
21
|
|
|
18
|
-
|
|
22
|
+
console.log(props?.options?.jsonSchemaYupTransfromer)
|
|
23
|
+
const formValidationSchema = computed(() => convertToYup(props.schema, props?.options?.jsonSchemaYupTransfromer ?? {}))
|
|
19
24
|
|
|
20
25
|
export type CustomValidation = {
|
|
21
26
|
field: string
|
|
@@ -31,8 +36,8 @@ const validateFields = async (fields: string[]) => {
|
|
|
31
36
|
}
|
|
32
37
|
}
|
|
33
38
|
|
|
34
|
-
if (props
|
|
35
|
-
for (const { field, message, validate } of props.customValidation) {
|
|
39
|
+
if (props?.options?.customValidation) {
|
|
40
|
+
for (const { field, message, validate } of props.options.customValidation) {
|
|
36
41
|
if (!fields.includes(field)) continue
|
|
37
42
|
if (!validate(value.value)) {
|
|
38
43
|
const errors = [{ path: field, message }]
|
|
@@ -54,13 +59,8 @@ const submit = () => {
|
|
|
54
59
|
<div>
|
|
55
60
|
{{ formRef ? formRef.errors : undefined }}
|
|
56
61
|
<UForm ref="formRef" :state="value" :schema="formValidationSchema" autocomplete="on" @submit="onSubmit">
|
|
57
|
-
<SComponent
|
|
58
|
-
|
|
59
|
-
v-bind="schema"
|
|
60
|
-
:validate-fields="validateFields"
|
|
61
|
-
@submit="submit"
|
|
62
|
-
:isRequired="true"
|
|
63
|
-
/>
|
|
62
|
+
<SComponent v-model="value" v-bind="schema" :validate-fields="validateFields" @submit="submit"
|
|
63
|
+
:isRequired="true" />
|
|
64
64
|
<slot />
|
|
65
65
|
|
|
66
66
|
<slot name="submit">
|