Skip to content

Commit

Permalink
fix(validatable): validate on blur after value has persisted
Browse files Browse the repository at this point in the history
changed process to match the internalValue watcher. need to wait for the value to update before
processing validation

fixes #10174
  • Loading branch information
johnleider committed Jan 10, 2020
1 parent 183d79b commit 33132a2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
2 changes: 1 addition & 1 deletion packages/vuetify/src/mixins/validatable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export default mixins(
!this.disabled
) {
this.hasFocused = true
this.validateOnBlur && this.validate()
this.validateOnBlur && this.$nextTick(this.validate)
}
},
isResetting () {
Expand Down

0 comments on commit 33132a2

Please sign in to comment.