From 33132a2277f50f3c20f56312a555e211dde30f25 Mon Sep 17 00:00:00 2001 From: John Leider Date: Fri, 10 Jan 2020 10:39:01 -0500 Subject: [PATCH] fix(validatable): validate on blur after value has persisted changed process to match the internalValue watcher. need to wait for the value to update before processing validation fixes #10174 --- .../validatable/__tests__/validatable.spec.ts | 31 +++++++++++++++++++ .../vuetify/src/mixins/validatable/index.ts | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/packages/vuetify/src/mixins/validatable/__tests__/validatable.spec.ts b/packages/vuetify/src/mixins/validatable/__tests__/validatable.spec.ts index d601dcedb9f..da8231411ee 100644 --- a/packages/vuetify/src/mixins/validatable/__tests__/validatable.spec.ts +++ b/packages/vuetify/src/mixins/validatable/__tests__/validatable.spec.ts @@ -444,4 +444,35 @@ describe('validatable.ts', () => { expect(wrapper.vm.validationState).toBeUndefined() expect(wrapper.vm.hasState).toBe(false) }) + + // https://github.com/vuetifyjs/vuetify/issues/10174 + it('should validate correct value when blurring', async () => { + const wrapper = mountFunction({ + propsData: { + rules: [v => !!v || 'Mandatory Field'], + validateOnBlur: true, + value: 'Foo', + }, + }) + + wrapper.setData({ isFocused: true }) + + wrapper.setProps({ value: '' }) + await wrapper.vm.$nextTick() + + wrapper.setData({ isFocused: false }) + await wrapper.vm.$nextTick() + + expect(wrapper.vm.hasError).toBe(true) + + wrapper.setData({ isFocused: true }) + + wrapper.setProps({ value: 'Bar' }) + await wrapper.vm.$nextTick() + + wrapper.setData({ isFocused: false }) + await wrapper.vm.$nextTick() + + expect(wrapper.vm.hasError).toBe(false) + }) }) diff --git a/packages/vuetify/src/mixins/validatable/index.ts b/packages/vuetify/src/mixins/validatable/index.ts index 0a22bbda524..6cce6108664 100644 --- a/packages/vuetify/src/mixins/validatable/index.ts +++ b/packages/vuetify/src/mixins/validatable/index.ts @@ -175,7 +175,7 @@ export default mixins( !this.disabled ) { this.hasFocused = true - this.validateOnBlur && this.validate() + this.validateOnBlur && this.$nextTick(this.validate) } }, isResetting () {