Skip to content

Commit 4bd415f

Browse files
feat(form): add required notice (#600)
1 parent 4c19e03 commit 4bd415f

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

app/components/VForm.vue

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,14 @@ const formattedSchema = computed(() => {
221221
return schema
222222
})
223223
224+
// REQUIRED FIELDS
225+
const hasRequiredFields = computed(() => {
226+
const required = formattedSchema.value?.required
227+
if (required === true) return true
228+
229+
return Array.isArray(required) && required.length > 0
230+
})
231+
224232
// CAPTCHA
225233
const captchaInputKey = computed(() => {
226234
const fieldKeys = Object.keys(toValue(formattedSchema.value?.properties) || {})
@@ -266,6 +274,13 @@ const isDisabled = computed(() => props.disabled || isPending.value || displayUs
266274
</button>
267275
</dialog>
268276
<slot name="beforeFields" />
277+
<p
278+
v-if="hasRequiredFields"
279+
:class="$style['required-notice']"
280+
class="text-body-xs"
281+
>
282+
{{ $t('form.required_fields_notice') }}
283+
</p>
269284
<VFormElementFactory
270285
:id="id"
271286
v-model="model"
@@ -324,6 +339,11 @@ const isDisabled = computed(() => props.disabled || isPending.value || displayUs
324339
z-index: 1;
325340
}
326341
342+
.required-notice {
343+
color: rgb(117 117 117);
344+
margin-block: 16px;
345+
}
346+
327347
.error {
328348
margin-block: 18px;
329349
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<script setup lang="ts">
2+
import type { JsonSchemaExtended } from '~~/types/json-schema'
3+
4+
const schema = {
5+
title: 'test',
6+
type: 'object',
7+
properties: {
8+
'texte': {
9+
type: 'string',
10+
title: 'Texte',
11+
},
12+
'mail': {
13+
type: 'string',
14+
title: 'Votre mail',
15+
attr: {
16+
'data-group': null,
17+
},
18+
description: 'mais votre vrai mail',
19+
widget: 'email',
20+
propertyOrder: 2,
21+
},
22+
'frc-captcha-response': {
23+
type: 'string',
24+
title: 'captcha',
25+
},
26+
},
27+
required: [],
28+
}
29+
</script>
30+
31+
<template>
32+
<NuxtStory>
33+
<VForm
34+
:schema="(schema as JsonSchemaExtended)"
35+
:gdpr="false"
36+
novalidate
37+
/>
38+
</NuxtStory>
39+
</template>

0 commit comments

Comments
 (0)