diff --git a/packages/vue-inertia/src/index.ts b/packages/vue-inertia/src/index.ts index 77b9b13..f6d201f 100644 --- a/packages/vue-inertia/src/index.ts +++ b/packages/vue-inertia/src/index.ts @@ -116,7 +116,7 @@ export const useForm = >(method: RequestMet throw new Error('The `value` is required.') } - errors = { key: value } + errors = { [key]: value } } else { errors = key } diff --git a/packages/vue-inertia/tests/index.test.ts b/packages/vue-inertia/tests/index.test.ts index 0fa25f6..2ee5a76 100644 --- a/packages/vue-inertia/tests/index.test.ts +++ b/packages/vue-inertia/tests/index.test.ts @@ -101,3 +101,13 @@ it('transforms data for validation requests', () => { expect(form.emails).toBe('taylor@laravel.com, tim@laravel.com') expect(form.data().emails).toBe('taylor@laravel.com, tim@laravel.com') }) + +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.') +})