mirror of
https://github.com/LukeHagar/form.git
synced 2025-12-09 20:37:47 +00:00
fix: field defaultValue should precedence over form defaultValues (#463)
* fix: field `defaultValue` should precedence over form `defaultValues` * chore: fix type * chore: format
This commit is contained in:
@@ -68,7 +68,7 @@ describe('useForm', () => {
|
||||
form.provideFormContext()
|
||||
|
||||
return () => (
|
||||
<form.Field name="firstName" defaultValue="">
|
||||
<form.Field name="firstName">
|
||||
{({ field }: { field: FieldApi<Person, 'firstName'> }) => (
|
||||
<p>{field.state.value}</p>
|
||||
)}
|
||||
@@ -81,6 +81,37 @@ describe('useForm', () => {
|
||||
expect(queryByText('LastName')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should use field default value first', async () => {
|
||||
type Person = {
|
||||
firstName: string
|
||||
lastName: string
|
||||
}
|
||||
|
||||
const formFactory = createFormFactory<Person>()
|
||||
|
||||
const Comp = defineComponent(() => {
|
||||
const form = formFactory.useForm({
|
||||
defaultValues: {
|
||||
firstName: 'FirstName',
|
||||
lastName: 'LastName',
|
||||
},
|
||||
})
|
||||
form.provideFormContext()
|
||||
|
||||
return () => (
|
||||
<form.Field name="firstName" defaultValue="otherName">
|
||||
{({ field }: { field: FieldApi<Person, 'firstName'> }) => (
|
||||
<p>{field.state.value}</p>
|
||||
)}
|
||||
</form.Field>
|
||||
)
|
||||
})
|
||||
|
||||
const { findByText, queryByText } = render(Comp)
|
||||
expect(await findByText('otherName')).toBeInTheDocument()
|
||||
expect(queryByText('LastName')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should handle submitting properly', async () => {
|
||||
const Comp = defineComponent(() => {
|
||||
const submittedData = ref<{ firstName: string }>()
|
||||
|
||||
Reference in New Issue
Block a user