fix: Fixed resetting field`s local errors when form errors prop cleared
This commit is contained in:
parent
20b08fe6e8
commit
75ee75f311
@ -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([])
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -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