Merge pull request #15 from 1on/dev
fix: Fixed resetting field`s local errors when form errors prop cleared
This commit is contained in:
commit
397fee45a3
@ -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([])
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -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)
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user