From 75ee75f311342adac02599e5e5eb9d1436098759 Mon Sep 17 00:00:00 2001 From: 1on Date: Thu, 12 Nov 2020 10:05:56 +0300 Subject: [PATCH] fix: Fixed resetting field`s local errors when form errors prop cleared --- src/validation/ErrorObserver.ts | 9 ++++++--- test/unit/FormularioForm.test.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/validation/ErrorObserver.ts b/src/validation/ErrorObserver.ts index 250536f..847a5e6 100644 --- a/src/validation/ErrorObserver.ts +++ b/src/validation/ErrorObserver.ts @@ -45,10 +45,13 @@ export class ErrorObserverRegistry { observer.callback(errors) } else if ( observer.field && - !Array.isArray(errors) && - has(errors, observer.field) + !Array.isArray(errors) ) { - observer.callback(errors[observer.field]) + if (has(errors, observer.field)) { + observer.callback(errors[observer.field]) + } else { + observer.callback([]) + } } }) } diff --git a/test/unit/FormularioForm.test.js b/test/unit/FormularioForm.test.js index 85106ac..9bd6d97 100644 --- a/test/unit/FormularioForm.test.js +++ b/test/unit/FormularioForm.test.js @@ -423,4 +423,32 @@ describe('FormularioForm', () => { expect(Object.keys(wrapper.vm.$refs.form.mergedFieldErrors).length).toBe(0) }) + + it('Local errors resetted when errors prop cleared', async () => { + const wrapper = mount({ + data: () => ({ values: {}, errors: { input: ['failure'] } }), + template: ` + + + {{ error.message }} + + + ` + }) + + await flushPromises() + expect(wrapper.find('span').exists()).toBe(true) + + wrapper.vm.errors = {} + await flushPromises() + expect(wrapper.find('span').exists()).toBe(false) + }) })