Skip to content

Commit

Permalink
[0.5.x] Use specified key for error key (#97)
Browse files Browse the repository at this point in the history
* Use specified key for error key

* lint
  • Loading branch information
timacdonald authored Sep 10, 2024
1 parent 1b09aa4 commit 59bec9d
Show file tree
Hide file tree
Showing 2 changed files with 11 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 @@ -116,7 +116,7 @@ export const useForm = <Data extends Record<string, unknown>>(method: RequestMet
throw new Error('The `value` is required.')
}

errors = { key: value }
errors = { [key]: value }
} else {
errors = key
}
Expand Down
10 changes: 10 additions & 0 deletions packages/vue-inertia/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,13 @@ it('transforms data for validation requests', () => {
expect(form.emails).toBe('[email protected], [email protected]')
expect(form.data().emails).toBe('[email protected], [email protected]')
})

it('can set individual errors', function () {
const form = useForm('post', '/register', {
name: '',
})

form.setError('name', 'The name is required.')

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

0 comments on commit 59bec9d

Please sign in to comment.