@dargmuesli/nuxt-vio 8.1.1 → 8.2.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,116 @@
|
|
1
|
+
<template>
|
2
|
+
<VioForm :form="v$" :is-form-sent="isFormSent" @submit="submit">
|
3
|
+
<input type="hidden" name="static-form-name" value="contact" />
|
4
|
+
<VioFormInput
|
5
|
+
id-label="input-name"
|
6
|
+
:placeholder="t('placeholderName')"
|
7
|
+
:title="t('name')"
|
8
|
+
type="text"
|
9
|
+
:value="v$.name"
|
10
|
+
@input="form.name = $event"
|
11
|
+
>
|
12
|
+
<template #stateError>
|
13
|
+
<!-- <VioFormInputStateError
|
14
|
+
:form-input="v$.name"
|
15
|
+
validation-property="maxLength"
|
16
|
+
>
|
17
|
+
{{ t('globalValidationLength') }}
|
18
|
+
</VioFormInputStateError> -->
|
19
|
+
<VioFormInputStateError
|
20
|
+
:form-input="v$.name"
|
21
|
+
validation-property="required"
|
22
|
+
>
|
23
|
+
{{ t('globalValidationRequired') }}
|
24
|
+
</VioFormInputStateError>
|
25
|
+
</template>
|
26
|
+
</VioFormInput>
|
27
|
+
<VioFormInputEmailAddress
|
28
|
+
:form-input="v$.emailAddress"
|
29
|
+
@input="form.emailAddress = $event"
|
30
|
+
/>
|
31
|
+
<VioFormInput
|
32
|
+
id-label="input-message"
|
33
|
+
:title="t('message')"
|
34
|
+
type="textarea"
|
35
|
+
:value="v$.message"
|
36
|
+
>
|
37
|
+
<textarea
|
38
|
+
v-if="v$.message"
|
39
|
+
:id="`${siteConfig.id}-${
|
40
|
+
runtimeConfig.public.vio.isInProduction ? 'prod' : 'dev'
|
41
|
+
}-input-message`"
|
42
|
+
class="form-input"
|
43
|
+
name="message"
|
44
|
+
:placeholder="t('placeholderMessage')"
|
45
|
+
rows="10"
|
46
|
+
:value="v$.message.$model"
|
47
|
+
@input="form.message = ($event.target as HTMLInputElement).value"
|
48
|
+
/>
|
49
|
+
<template #stateError>
|
50
|
+
<!-- <VioFormInputStateError
|
51
|
+
:form-input="v$.message"
|
52
|
+
validation-property="maxLength"
|
53
|
+
>
|
54
|
+
{{ t('globalValidationLength') }}
|
55
|
+
</VioFormInputStateError> -->
|
56
|
+
<VioFormInputStateError
|
57
|
+
:form-input="v$.message"
|
58
|
+
validation-property="required"
|
59
|
+
>
|
60
|
+
{{ t('globalValidationRequired') }}
|
61
|
+
</VioFormInputStateError>
|
62
|
+
</template>
|
63
|
+
</VioFormInput>
|
64
|
+
</VioForm>
|
65
|
+
</template>
|
66
|
+
|
67
|
+
<script setup lang="ts">
|
68
|
+
import { useVuelidate } from '@vuelidate/core'
|
69
|
+
import { required } from '@vuelidate/validators'
|
70
|
+
|
71
|
+
const { t } = useI18n()
|
72
|
+
const runtimeConfig = useRuntimeConfig()
|
73
|
+
const siteConfig = useSiteConfig()
|
74
|
+
|
75
|
+
// data
|
76
|
+
const form = reactive({
|
77
|
+
emailAddress: ref<string>(),
|
78
|
+
name: ref<string>(),
|
79
|
+
message: ref<string>(),
|
80
|
+
})
|
81
|
+
const isFormSent = ref(false)
|
82
|
+
|
83
|
+
// methods
|
84
|
+
const submit = async (e: Event) =>
|
85
|
+
!(await isFormValid({ v$, isFormSent })) ? e.preventDefault() : undefined
|
86
|
+
|
87
|
+
// vuelidate
|
88
|
+
const rules = {
|
89
|
+
emailAddress: {
|
90
|
+
// maxLength: maxLength(100),
|
91
|
+
required,
|
92
|
+
},
|
93
|
+
name: {
|
94
|
+
// maxLength: maxLength(250),
|
95
|
+
required,
|
96
|
+
},
|
97
|
+
message: {
|
98
|
+
// maxLength: maxLength(100),
|
99
|
+
required,
|
100
|
+
},
|
101
|
+
}
|
102
|
+
const v$ = useVuelidate(rules, form)
|
103
|
+
</script>
|
104
|
+
|
105
|
+
<i18n lang="yaml">
|
106
|
+
de:
|
107
|
+
message: Nachricht
|
108
|
+
name: Name
|
109
|
+
placeholderMessage: Guten Tag, …
|
110
|
+
placeholderName: Manu Musterperson
|
111
|
+
en:
|
112
|
+
message: Message
|
113
|
+
name: Name
|
114
|
+
placeholderMessage: Hello, …
|
115
|
+
placeholderName: Person Doe
|
116
|
+
</i18n>
|
@@ -43,6 +43,7 @@
|
|
43
43
|
}"
|
44
44
|
:disabled="isDisabled"
|
45
45
|
:placeholder="placeholder"
|
46
|
+
:name="name || idLabelFull"
|
46
47
|
:readonly="isReadonly"
|
47
48
|
:type="type"
|
48
49
|
:value="valueFormatter(value?.$model as string)"
|
@@ -119,12 +120,13 @@ import type { BaseValidation } from '@vuelidate/core'
|
|
119
120
|
import { consola } from 'consola'
|
120
121
|
|
121
122
|
export interface Props {
|
123
|
+
idLabel?: string
|
122
124
|
isDisabled?: boolean
|
123
125
|
isOptional?: boolean
|
124
126
|
isReadonly?: boolean
|
125
127
|
isRequired?: boolean
|
126
128
|
isValidatable?: boolean
|
127
|
-
|
129
|
+
name?: string
|
128
130
|
placeholder?: string
|
129
131
|
success?: boolean
|
130
132
|
title: string
|
@@ -135,12 +137,13 @@ export interface Props {
|
|
135
137
|
warning?: boolean
|
136
138
|
}
|
137
139
|
const props = withDefaults(defineProps<Props>(), {
|
140
|
+
idLabel: undefined,
|
138
141
|
isDisabled: false,
|
139
142
|
isOptional: false,
|
140
143
|
isReadonly: false,
|
141
144
|
isRequired: false,
|
142
145
|
isValidatable: false,
|
143
|
-
|
146
|
+
name: undefined,
|
144
147
|
placeholder: undefined,
|
145
148
|
success: false,
|
146
149
|
type: undefined,
|
@@ -158,12 +161,13 @@ const emit = defineEmits<{
|
|
158
161
|
|
159
162
|
const { t } = useI18n()
|
160
163
|
const runtimeConfig = useRuntimeConfig()
|
164
|
+
const siteConfig = useSiteConfig()
|
161
165
|
|
162
166
|
// data
|
163
167
|
const idLabelFull = props.idLabel
|
164
|
-
?
|
165
|
-
|
166
|
-
}`
|
168
|
+
? `${siteConfig.id}-${
|
169
|
+
runtimeConfig.public.vio.isInProduction ? 'prod' : 'dev'
|
170
|
+
}-${props.idLabel}`
|
167
171
|
: undefined
|
168
172
|
|
169
173
|
// initialization
|
package/nuxt.config.ts
CHANGED