From 06c79905a850444e711781b4356a68884ffefd49 Mon Sep 17 00:00:00 2001 From: 1on Date: Tue, 20 Oct 2020 18:26:41 +0300 Subject: [PATCH] fix: Removed validation on field value change, when errorBehavior is not live --- src/FormularioInput.vue | 6 +++++- test/unit/FormularioInput.test.js | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/FormularioInput.vue b/src/FormularioInput.vue index 61245ce..5bad20d 100644 --- a/src/FormularioInput.vue +++ b/src/FormularioInput.vue @@ -276,7 +276,11 @@ export default class FormularioInput extends Vue { @Watch('proxy') onProxyChanged (newValue, oldValue): void { - this.performValidation() + if (this.errorBehavior === ERROR_BEHAVIOR.LIVE) { + this.performValidation() + } else { + this.validationErrors = [] + } if (!this.isVmodeled && !shallowEqualObjects(newValue, oldValue)) { this.context.model = newValue } diff --git a/test/unit/FormularioInput.test.js b/test/unit/FormularioInput.test.js index 81057ce..8ab155e 100644 --- a/test/unit/FormularioInput.test.js +++ b/test/unit/FormularioInput.test.js @@ -58,6 +58,33 @@ describe('FormularioInput', () => { expect(wrapper.find('span').exists()).toBe(false) }) + it('no validation on value change when errorBehavior is not live', async () => { + const wrapper = mount(FormularioInput, { + propsData: { + name: 'test', + validation: 'required|in:abcdef', + validationMessages: {in: 'the value was different than expected'}, + errorBehavior: 'submit', + value: 'other value' + }, + scopedSlots: { + default: `
+ + {{ error.message }} +
` + } + }) + await flushPromises() + expect(wrapper.find('span').exists()).toBe(false) + + const input = wrapper.find('input[type="text"]') + input.element.value = 'test' + input.trigger('input') + await flushPromises() + expect(wrapper.find('input[type="text"]').element.value).toBe('test') + expect(wrapper.find('span').exists()).toBe(false) + }) + it('allows custom field-rule level validation functions', async () => { const wrapper = mount(FormularioInput, { propsData: {