fix(FormField): restore eager-validation prop behavior (#3031)

Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
Romain Hamel
2025-01-06 18:48:10 +01:00
committed by Benjamin Canac
parent 00b3c86584
commit 41dc11ceef
5 changed files with 51 additions and 13 deletions

View File

@@ -89,7 +89,7 @@ describe('Textarea', () => {
})
describe('form integration', async () => {
async function createForm(validateOn?: FormInputEvents[]) {
async function createForm(validateOn?: FormInputEvents[], eagerValidation?: boolean) {
const wrapper = await renderForm({
props: {
validateOn,
@@ -101,10 +101,13 @@ describe('Textarea', () => {
}
},
slotTemplate: `
<UFormField name="value">
<UFormField name="value" :eager-validation="eagerValidation">
<UTextarea id="input" v-model="state.value" />
</UFormField>
`
`,
slotVars: {
eagerValidation
}
})
const input = wrapper.find('#input')
return {
@@ -134,7 +137,22 @@ describe('Textarea', () => {
})
test('validate on input works', async () => {
const { input, wrapper } = await createForm(['input'], true)
await input.setValue('value')
expect(wrapper.text()).toContain('Error message')
await input.setValue('valid')
expect(wrapper.text()).not.toContain('Error message')
})
test('validate on input without eager validation works', async () => {
const { input, wrapper } = await createForm(['input'])
await input.setValue('value')
expect(wrapper.text()).not.toContain('Error message')
await input.trigger('blur')
await input.setValue('value')
expect(wrapper.text()).toContain('Error message')