Skip to content

Commit

Permalink
fix(validation): set input to invalid using error/errorMessages (#15269)
Browse files Browse the repository at this point in the history
closes #15209
  • Loading branch information
nekosaur committed Jun 30, 2022
1 parent 6ad0dc1 commit 2d91603
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions packages/vuetify/src/composables/__tests__/validation.spec.ts
Expand Up @@ -109,4 +109,34 @@ describe('validation', () => {
expect(wrapper.vm.isPristine).toBe(true)
expect(wrapper.vm.isValid).toBeNull()
})

it('should return valid if no rules are set', async () => {
const wrapper = mountFunction()

expect(wrapper.vm.isValid).toBe(true)

await wrapper.setProps({ rules: [] })

expect(wrapper.vm.isValid).toBe(true)

await wrapper.setProps({ error: true })

expect(wrapper.vm.isValid).toBe(false)
})

it('should return invalid if error is manually set', async () => {
const wrapper = mountFunction({
error: true,
})

expect(wrapper.vm.isValid).toBe(false)

await wrapper.setProps({ error: false, errorMessages: ['error'] })

expect(wrapper.vm.isValid).toBe(false)

await wrapper.setProps({ errorMessages: [] })

expect(wrapper.vm.isValid).toBe(true)
})
})
2 changes: 1 addition & 1 deletion packages/vuetify/src/composables/validation.ts
Expand Up @@ -73,8 +73,8 @@ export function useValidation (
: internalErrorMessages.value
})
const isValid = computed(() => {
if (!props.rules.length) return true
if (props.error || errorMessages.value.length) return false
if (!props.rules.length) return true

return isPristine.value ? null : true
})
Expand Down

0 comments on commit 2d91603

Please sign in to comment.