Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions packages/form-core/tests/standardSchemaValidator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,43 @@ describe('standard schema validator', () => {
])
})
})

it('should handle multiple errors on a field', () => {
const form = new FormApi({
defaultValues: {
name: '',
},
})
const field = new FieldApi({
form,
name: 'name',
validators: {
onChange: z
.string()
.min(3, 'You must have a length of at least 3')
.regex(/^[a-z]+$/i, 'You must have only letters'),
},
})

field.mount()

// valid by default
expect(field.getMeta().errors).toEqual([])

// too short
field.setValue('a')
expect(field.getMeta().errors).toEqual([
'You must have a length of at least 3',
])

// too short and invalid character
field.setValue('a#')
expect(field.getMeta().errors).toEqual([
'You must have a length of at least 3',
'You must have only letters',
])

// valid
field.setValue('asdf')
expect(field.getMeta().errors).toEqual([])
})
Loading