Skip to content

Commit

Permalink
feat: add onSubmit listener
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry Whorlow committed Nov 22, 2024
1 parent ebcdf83 commit 72b762b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/form-core/src/FieldApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,13 @@ export interface FieldListeners<
TFormValidator,
TData
>
onSubmit?: FieldListenerFn<
TParentData,
TName,
TFieldValidator,
TFormValidator,
TData
>
}

/**
Expand Down
24 changes: 24 additions & 0 deletions packages/form-core/tests/FieldApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,30 @@ describe('field api', () => {
expect(triggered).toStrictEqual('test')
})

it('should run listener onSubmit', () => {
const form = new FormApi({
defaultValues: {
name: 'test',
},
})

let triggered!: string
const field = new FieldApi({
form,
name: 'name',
listeners: {
onSubmit: ({ value }) => {
triggered = value
},
},
})

field.mount()
form.handleSubmit()

expect(triggered).toStrictEqual('test')
})

it('should contain multiple errors when running validation onBlur and onChange', () => {
const form = new FormApi({
defaultValues: {
Expand Down

0 comments on commit 72b762b

Please sign in to comment.