FormField 형식필드
Usage
양식 구성 요소를 FormField로 래핑합니다. Form에서 사용되며 유효성 검사 및 오류 처리를 제공합니다.
Label 태그
label Prop을 사용하여 양식 컨트롤의 레이블을 설정합니다.
<template>
<UFormField label="Email">
<UInput placeholder="Enter your email" />
</UFormField>
</template>for 특성 및 양식 컨트롤은 제공되지 않은 경우 고유 id와 연결됩니다.required 소품을 사용할 때 레이블 옆에 별표가 추가됩니다.
<template>
<UFormField label="Email" required>
<UInput placeholder="Enter your email" />
</UFormField>
</template>Description
description prop을 사용하여 레이블 아래에 추가 정보를 제공합니다.
We'll never share your email with anyone else.
<template>
<UFormField label="Email" description="We'll never share your email with anyone else.">
<UInput placeholder="Enter your email" class="w-full" />
</UFormField>
</template>힌트
hint Prop을 사용하여 레이블 옆에 힌트 메시지를 표시합니다.
<template>
<UFormField label="Email" hint="Optional">
<UInput placeholder="Enter your email" />
</UFormField>
</template>Help 지원
help prop을 사용하여 양식 컨트롤 아래에 도움말 메시지를 표시합니다. error prop과 함께 사용할 때 error prop이 우선적으로 사용됩니다.
<template>
<UFormField label="Email" help="Please enter a valid email address.">
<UInput placeholder="Enter your email" class="w-full" />
</UFormField>
</template>Error 오류
error Prop을 사용하여 양식 컨트롤 아래에 오류 메시지를 표시합니다. help Prop과 함께 사용할 때 error Prop이 우선합니다.
Form 내부에서 사용할 경우 유효성 검사 오류가 발생할 때 자동으로 설정됩니다.
<template>
<UFormField label="Email" error="Please enter a valid email address.">
<UInput placeholder="Enter your email" class="w-full" />
</UFormField>
</template>error 패턴
error-pattern prop을 사용하여 양식 오류를 정규 표현식과 일치시킵니다. 이는 특히 InputTags와 같은 배열 값을 가진 구성 요소에 관련이 있으며, 여기서 오류는 tags.0와 같은 이름에 배열 인덱스를 포함합니다.
Size 크기
size prop을 사용하여 FormField의 크기를 변경하면 size가 폼 컨트롤에 프록시됩니다.
We'll never share your email with anyone else.
<template>
<UFormField
label="Email"
description="We'll never share your email with anyone else."
hint="Optional"
help="Please enter a valid email address."
size="xl"
>
<UInput placeholder="Enter your email" class="w-full" />
</UFormField>
</template>방향 : badge{label="4.3+" class="align-text-top"}
orientation prop을 사용하여 FormField.Defaults의 레이아웃을 vertical로 변경합니다.
<template>
<UFormField
orientation="horizontal"
label="Email"
help="Please enter a valid email address."
class="w-72"
>
<UInput placeholder="Enter your email" class="w-full" />
</UFormField>
</template>API 파일
Props 코드
| Prop | Default | Type |
|---|---|---|
as | 'div' | anyThe element or component this component should render as. |
name | stringThe name of the FormField. Also used to match form errors. | |
errorPattern | RegExpA regular expression to match form error names. Useful for components with array values such as InputTags, where errors include array indices in their name (e.g. | |
label | string | |
description | string | |
help | string | |
error | undefined | string | false | true |
hint | string | |
size | 'md' | "md" | "xs" | "sm" | "lg" | "xl" |
required | boolean | |
eagerValidation | boolean If true, validation on input will be active immediately instead of waiting for a blur event. | |
validateOnInputDelay | `300` | numberDelay in milliseconds before validating the form on input events. |
orientation | 'vertical' | "vertical" | "horizontal"The orientation of the form field. |
ui | { root?: SlotClass; wrapper?: SlotClass; labelWrapper?: SlotClass; label?: SlotClass; container?: SlotClass; description?: SlotClass; error?: SlotClass; hint?: SlotClass; help?: SlotClass; } |
슬롯
| Slot | Type |
|---|---|
label | { label: string | undefined; } |
hint | { hint: string | undefined; } |
description | { description: string | undefined; } |
help | { help: string | undefined; } |
error | { error: string | true | undefined; } |
default | { error: string | true | undefined; } |
Theme (## 테마)
export default defineAppConfig({
ui: {
formField: {
slots: {
root: '',
wrapper: '',
labelWrapper: 'flex content-center items-center justify-between gap-1',
label: 'block font-medium text-default',
container: 'relative',
description: 'text-muted',
error: 'mt-2 text-error',
hint: 'text-muted',
help: 'mt-2 text-muted'
},
variants: {
size: {
xs: {
root: 'text-xs'
},
sm: {
root: 'text-xs'
},
md: {
root: 'text-sm'
},
lg: {
root: 'text-sm'
},
xl: {
root: 'text-base'
}
},
required: {
true: {
label: "after:content-['*'] after:ms-0.5 after:text-error"
}
},
orientation: {
vertical: {
container: 'mt-1'
},
horizontal: {
root: 'flex justify-between place-items-baseline gap-2'
}
}
},
defaultVariants: {
size: 'md'
}
}
}
})import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nuxt/ui/vite'
export default defineConfig({
plugins: [
vue(),
ui({
ui: {
formField: {
slots: {
root: '',
wrapper: '',
labelWrapper: 'flex content-center items-center justify-between gap-1',
label: 'block font-medium text-default',
container: 'relative',
description: 'text-muted',
error: 'mt-2 text-error',
hint: 'text-muted',
help: 'mt-2 text-muted'
},
variants: {
size: {
xs: {
root: 'text-xs'
},
sm: {
root: 'text-xs'
},
md: {
root: 'text-sm'
},
lg: {
root: 'text-sm'
},
xl: {
root: 'text-base'
}
},
required: {
true: {
label: "after:content-['*'] after:ms-0.5 after:text-error"
}
},
orientation: {
vertical: {
container: 'mt-1'
},
horizontal: {
root: 'flex justify-between place-items-baseline gap-2'
}
}
},
defaultVariants: {
size: 'md'
}
}
}
})
]
})