Skip to content

Commit

Permalink
Allow getter as inputs for vue-inertia
Browse files Browse the repository at this point in the history
  • Loading branch information
parafeu committed Feb 4, 2025
1 parent 674ee5a commit 588c631
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/vue-inertia/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Form } from './types'

export { client }

export const useForm = <Data extends Record<string, unknown>>(method: RequestMethod | (() => RequestMethod), url: string | (() => string), inputs: Data, config: ValidationConfig = {}): Form<Data> => {
export const useForm = <Data extends Record<string, unknown>>(method: RequestMethod | (() => RequestMethod), url: string | (() => string), inputs: Data | (() => Data), config: ValidationConfig = {}): Form<Data> => {
/**
* The Inertia form.
*/
Expand Down
19 changes: 19 additions & 0 deletions packages/vue-inertia/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,22 @@ it('can set individual errors', function () {

expect(form.errors.name).toBe('The name is required.')
})

it('allows getter as data inputs', function () {
let dynamicEmail = '[email protected]'

function getData() {
return {
email: dynamicEmail,
}
}

const form = useForm('post', '/register', getData)

expect(form.email).toBe('[email protected]')

dynamicEmail = '[email protected]'
form.reset()

expect(form.email).toBe('[email protected]')
})

0 comments on commit 588c631

Please sign in to comment.