From 4c49648860d0679ac2a494c0f5ee03359ff4dda8 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Tue, 10 Sep 2024 09:44:53 +1000 Subject: [PATCH 1/2] Use specified key for error key --- packages/vue-inertia/src/index.ts | 2 +- packages/vue-inertia/tests/index.test.ts | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) 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..824270e 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.') +}) From 21e22f4a2bf7627ae1beb6a91fcb90b126358391 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Tue, 10 Sep 2024 09:50:05 +1000 Subject: [PATCH 2/2] lint --- packages/vue-inertia/tests/index.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vue-inertia/tests/index.test.ts b/packages/vue-inertia/tests/index.test.ts index 824270e..2ee5a76 100644 --- a/packages/vue-inertia/tests/index.test.ts +++ b/packages/vue-inertia/tests/index.test.ts @@ -105,7 +105,7 @@ it('transforms data for validation requests', () => { it('can set individual errors', function () { const form = useForm('post', '/register', { name: '', - }); + }) form.setError('name', 'The name is required.')