Skip to content

Commit 588c631

Browse files
committed
Allow getter as inputs for vue-inertia
1 parent 674ee5a commit 588c631

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

packages/vue-inertia/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Form } from './types'
77

88
export { client }
99

10-
export const useForm = <Data extends Record<string, unknown>>(method: RequestMethod | (() => RequestMethod), url: string | (() => string), inputs: Data, config: ValidationConfig = {}): Form<Data> => {
10+
export const useForm = <Data extends Record<string, unknown>>(method: RequestMethod | (() => RequestMethod), url: string | (() => string), inputs: Data | (() => Data), config: ValidationConfig = {}): Form<Data> => {
1111
/**
1212
* The Inertia form.
1313
*/

packages/vue-inertia/tests/index.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,22 @@ it('can set individual errors', function () {
111111

112112
expect(form.errors.name).toBe('The name is required.')
113113
})
114+
115+
it('allows getter as data inputs', function () {
116+
let dynamicEmail = '[email protected]'
117+
118+
function getData() {
119+
return {
120+
email: dynamicEmail,
121+
}
122+
}
123+
124+
const form = useForm('post', '/register', getData)
125+
126+
expect(form.email).toBe('[email protected]')
127+
128+
dynamicEmail = '[email protected]'
129+
form.reset()
130+
131+
expect(form.email).toBe('[email protected]')
132+
})

0 commit comments

Comments
 (0)