fix(Form): added name to fieldState (#643)
This commit is contained in:
parent
f03778304d
commit
d50ea38f4a
|
|
@ -6,19 +6,19 @@ export function useFormField() {
|
||||||
const fieldContext = inject(FieldContextKey)
|
const fieldContext = inject(FieldContextKey)
|
||||||
const fieldItemContext = inject(FORM_ITEM_INJECTION_KEY)
|
const fieldItemContext = inject(FORM_ITEM_INJECTION_KEY)
|
||||||
|
|
||||||
const fieldState = {
|
|
||||||
valid: useIsFieldValid(),
|
|
||||||
isDirty: useIsFieldDirty(),
|
|
||||||
isTouched: useIsFieldTouched(),
|
|
||||||
error: useFieldError(),
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fieldContext)
|
if (!fieldContext)
|
||||||
throw new Error('useFormField should be used within <FormField>')
|
throw new Error('useFormField should be used within <FormField>')
|
||||||
|
|
||||||
const { name } = fieldContext
|
const { name } = fieldContext
|
||||||
const id = fieldItemContext
|
const id = fieldItemContext
|
||||||
|
|
||||||
|
const fieldState = {
|
||||||
|
valid: useIsFieldValid(name),
|
||||||
|
isDirty: useIsFieldDirty(name),
|
||||||
|
isTouched: useIsFieldTouched(name),
|
||||||
|
error: useFieldError(name),
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,6 @@ import { FORM_ITEM_INJECTION_KEY } from './injectionKeys'
|
||||||
export function useFormField() {
|
export function useFormField() {
|
||||||
const fieldContext = inject(FieldContextKey)
|
const fieldContext = inject(FieldContextKey)
|
||||||
const fieldItemContext = inject(FORM_ITEM_INJECTION_KEY)
|
const fieldItemContext = inject(FORM_ITEM_INJECTION_KEY)
|
||||||
const fieldState = {
|
|
||||||
valid: useIsFieldValid(),
|
|
||||||
isDirty: useIsFieldDirty(),
|
|
||||||
isTouched: useIsFieldTouched(),
|
|
||||||
error: useFieldError(),
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fieldContext)
|
if (!fieldContext)
|
||||||
throw new Error('useFormField should be used within <FormField>')
|
throw new Error('useFormField should be used within <FormField>')
|
||||||
|
|
@ -18,6 +12,13 @@ export function useFormField() {
|
||||||
const { name } = fieldContext
|
const { name } = fieldContext
|
||||||
const id = fieldItemContext
|
const id = fieldItemContext
|
||||||
|
|
||||||
|
const fieldState = {
|
||||||
|
valid: useIsFieldValid(name),
|
||||||
|
isDirty: useIsFieldDirty(name),
|
||||||
|
isTouched: useIsFieldTouched(name),
|
||||||
|
error: useFieldError(name),
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user