1
0
mirror of synced 2024-11-25 06:46:02 +03:00

Merge pull request #15 from 1on/dev

fix: Fixed resetting field`s local errors when form errors prop cleared
This commit is contained in:
Kruglov Kirill 2020-11-12 10:11:36 +03:00 committed by GitHub
commit 397fee45a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 3 deletions

View File

@ -45,10 +45,13 @@ export class ErrorObserverRegistry {
observer.callback(errors)
} else if (
observer.field &&
!Array.isArray(errors) &&
has(errors, observer.field)
!Array.isArray(errors)
) {
if (has(errors, observer.field)) {
observer.callback(errors[observer.field])
} else {
observer.callback([])
}
}
})
}

View File

@ -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: `
<FormularioForm
v-model="values"
:errors="errors"
ref="form"
>
<FormularioInput
v-slot="{ context }"
name="input"
ref="form"
>
<span v-for="error in context.allErrors">{{ error.message }}</span>
</FormularioInput>
</FormularioForm>
`
})
await flushPromises()
expect(wrapper.find('span').exists()).toBe(true)
wrapper.vm.errors = {}
await flushPromises()
expect(wrapper.find('span').exists()).toBe(false)
})
})