1
0
mirror of synced 2024-11-22 05:16:05 +03:00

fix: Fixed resetting field`s local errors when form errors prop cleared

This commit is contained in:
1on 2020-11-12 10:05:56 +03:00
parent 20b08fe6e8
commit 75ee75f311
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)
})
})