Skip to content

Commit

Permalink
fix(validation): don't truncate error message passed as string (#16246)
Browse files Browse the repository at this point in the history
fixes #16242
  • Loading branch information
jacekkarczmarczyk committed Dec 10, 2022
1 parent c48d7e4 commit 3688c00
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 18 additions & 0 deletions packages/vuetify/src/composables/__tests__/validation.spec.ts
Expand Up @@ -41,6 +41,7 @@ describe('validation', () => {

it.each([
[undefined, 1],
[0, 0],
[1, 1],
[2, 2],
[3, 3],
Expand All @@ -59,6 +60,7 @@ describe('validation', () => {

it.each([
[undefined, 1],
[0, 0],
[1, 1],
[2, 2],
[3, 3],
Expand All @@ -75,6 +77,22 @@ describe('validation', () => {
expect(wrapper.vm.errorMessages).toHaveLength(expected)
})

it.each([
[undefined, ['foo']],
[0, []],
[1, ['foo']],
[2, ['foo']],
])('should not trim error message if passed as text', async (maxErrors, expected) => {
const wrapper = mountFunction({
maxErrors,
errorMessages: 'foo',
})

await wrapper.vm.validate()

expect(wrapper.vm.errorMessages).toStrictEqual(expected)
})

it('should warn the user when using an improper rule fn', async () => {
const rule = (v: any) => !!v || 1234
const wrapper = mountFunction({
Expand Down
4 changes: 2 additions & 2 deletions packages/vuetify/src/composables/validation.ts
Expand Up @@ -78,7 +78,7 @@ export function useValidation (
const isReadonly = computed(() => !!(props.readonly || form?.isReadonly.value))
const errorMessages = computed(() => {
return props.errorMessages.length
? wrapInArray(props.errorMessages.slice(0, Math.max(0, +props.maxErrors)))
? wrapInArray(props.errorMessages).slice(0, Math.max(0, +props.maxErrors))
: internalErrorMessages.value
})
const isValid = computed(() => {
Expand Down Expand Up @@ -157,7 +157,7 @@ export function useValidation (
isValidating.value = true

for (const rule of props.rules) {
if (results.length >= (props.maxErrors || 1)) {
if (results.length >= (props.maxErrors ?? 1)) {
break
}

Expand Down

0 comments on commit 3688c00

Please sign in to comment.