Skip to content

Commit a6e55a5

Browse files
committed
feat: add multiple UFormField configuration options
1 parent 4c19c6b commit a6e55a5

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed

playground/app/components/MyForm.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ const ENUM_MULTIPLE = [
1313
const schema = z.object({
1414
text: z.string()
1515
.nonempty()
16-
.meta({ title: 'Text Input' }),
16+
.meta({ title: 'Text Input', required: true }),
1717
enum: z.enum(['1', '2', '3'])
1818
.meta({ title: 'Enum Input' }),
1919
text_description: z.string()
2020
.meta({
2121
description: 'with description',
22+
hint: 'with hint',
2223
}),
2324
custom_bool: z.boolean()
2425
.meta({ title: 'Input with custom slot' }),

playground/tests/e2e/basic.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ test('test very basic form', async ({ page }) => {
99
await page.getByRole('combobox', { name: 'Enum Input', exact: true }).click()
1010
await page.getByRole('option', { name: '2' }).click()
1111
await page.getByRole('textbox', { name: 'Text description' }).click()
12+
await expect(page.getByText('with description')).toBeVisible()
13+
await expect(page.getByText('with hint')).toBeVisible()
1214
await page.locator('form div').filter({ hasText: 'Input with custom slot' }).getByRole('combobox').click()
1315
await page.getByLabel('True').getByText('True').click()
1416
await expect(page.locator('#v-4-error')).toContainText('Invalid input')

src/runtime/components/AutoForm.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ function parseMeta(zodType: any, key: string) {
8989
9090
return {
9191
label: meta.title ?? upperFirst(splitByCase(key).join(' ').toLowerCase()),
92+
required: meta.required,
9293
description: meta.description,
94+
hint: meta.hint,
95+
help: meta.help,
9396
class: meta.autoForm?.floatRight ? 'flex items-center justify-between text-left' : '',
9497
}
9598
}

src/runtime/types/zod.d.ts

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,58 @@
11
// Generated by Nuxt Auto Form
22

33
declare module 'zod' {
4+
/** Global configuration added by `nuxt-auto-form` Nuxt module */
45
interface GlobalMeta {
5-
/** Configuration related to `nuxt-auto-form` Nuxt module */
6+
/** Auto-form specific configuration */
67
autoForm?: {
7-
/** Float input box to the right of the label */
8+
/** Float the input box to the right of the label */
89
floatRight?: boolean
910
}
11+
12+
input?: object
13+
14+
/**
15+
* Field label displayed in the form's label row.
16+
* Maps directly to `UFormField.label`.
17+
*
18+
* @remarks Added by `nuxt-auto-form`
19+
* @default Field name in PascalCase with spaces
20+
* @see https://ui.nuxt.com/components/form-field#description
21+
*/
22+
title?: string
23+
24+
/**
25+
* Marks the field as required in the UI (asterisk, aria-required).
26+
* Validation is not enforced here; use `zod` refinements for that.
27+
*
28+
* @remarks Added by `nuxt-auto-form`
29+
* @see https://ui.nuxt.com/components/form-field#required
30+
*/
31+
required?: boolean
32+
33+
/**
34+
* Supporting text displayed between the label and the input control.
35+
*
36+
* @remarks Added by `nuxt-auto-form`
37+
* @see https://ui.nuxt.com/components/form-field#description
38+
*/
39+
description?: string
40+
41+
/**
42+
* Short inline hint shown next to the label.
43+
*
44+
* @remarks Added by `nuxt-auto-form`
45+
* @see https://ui.nuxt.com/components/form-field#hint
46+
*/
47+
hint?: string
48+
49+
/**
50+
* Help text displayed below the input field.
51+
*
52+
* @remarks Added by `nuxt-auto-form`
53+
* @see https://ui.nuxt.com/components/form-field#help
54+
*/
55+
help?: string
1056
}
1157
}
1258

0 commit comments

Comments
 (0)