Skip to content

Commit

Permalink
fix(Form)!: include nested state in submit data
Browse files Browse the repository at this point in the history
  • Loading branch information
romhml committed Jan 6, 2025
1 parent 561fcd0 commit 517acae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/runtime/components/Form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ async function _validate(opts: { name?: string | string[], silent?: boolean, nes
throw new FormValidationException(formId, errors.value, childErrors)
}
Object.assign(props.state, parsedValue.value)
return props.state as T
}
Expand All @@ -169,8 +171,7 @@ async function onSubmitWrapper(payload: Event) {
const event = payload as FormSubmitEvent<any>
try {
await _validate({ nested: true })
event.data = props.schema ? parsedValue.value : props.state
event.data = await _validate({ nested: true })
await props.onSubmit?.(event)
} catch (error) {
if (!(error instanceof FormValidationException)) {
Expand Down
9 changes: 9 additions & 0 deletions test/components/Form.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,15 @@ describe('Form', () => {
expect(nestedField.text()).toBe('Required')
})

test('submit event contains nested attributes', async () => {
state.email = 'bob@dylan.com'
state.password = 'strongpassword'
state.nested.field = 'nested'

await form.value.submit()
expect(wrapper.setupState.onSubmit).toHaveBeenCalledWith(expect.objectContaining({ data: { email: 'bob@dylan.com', password: 'strongpassword', nested: { field: 'nested' } } }))
})

test('submit works when child is disabled', async () => {
await form.value.submit()
expect(wrapper.setupState.onError).toHaveBeenCalledTimes(1)
Expand Down

0 comments on commit 517acae

Please sign in to comment.