Skip to content

Commit

Permalink
fix(Form): return state on validate (#472)
Browse files Browse the repository at this point in the history
  • Loading branch information
romhml authored Aug 1, 2023
1 parent 396aae7 commit 248b0a6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
8 changes: 4 additions & 4 deletions docs/components/content/examples/FormExampleJoi.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { ref } from 'vue'
import Joi from 'joi'
const schema = Joi.object({
email: Joi.string().required(),
password: Joi.string()
emailJoi: Joi.string().required(),
passwordJoi: Joi.string()
.min(8)
.required()
})
Expand All @@ -29,11 +29,11 @@ async function submit () {
:state="state"
@submit.prevent="submit"
>
<UFormGroup label="Email" name="email-joi">
<UFormGroup label="Email" name="emailJoi">
<UInput v-model="state.email" />
</UFormGroup>

<UFormGroup label="Password" name="password-joi">
<UFormGroup label="Password" name="passwordJoi">
<UInput v-model="state.password" type="password" />
</UFormGroup>

Expand Down
8 changes: 4 additions & 4 deletions docs/components/content/examples/FormExampleYup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { object, string, InferType } from 'yup'
import type { Form } from '@nuxthq/ui/dist/runtime/types'
const schema = object({
email: string().email('Invalid email').required('Required'),
password: string()
emailYup: string().email('Invalid email').required('Required'),
passwordYup: string()
.min(8, 'Must be at least 8 characters')
.required('Required')
})
Expand All @@ -32,11 +32,11 @@ async function submit () {
:state="state"
@submit.prevent="submit"
>
<UFormGroup label="Email" name="email-yup">
<UFormGroup label="Email" name="emailYup">
<UInput v-model="state.email" />
</UFormGroup>

<UFormGroup label="Password" name="password-yup">
<UFormGroup label="Password" name="passwordYup">
<UInput v-model="state.password" type="password" />
</UFormGroup>

Expand Down
8 changes: 4 additions & 4 deletions docs/components/content/examples/FormExampleZod.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { z } from 'zod'
import type { Form } from '@nuxthq/ui/dist/runtime/types'
const schema = z.object({
email: z.string().email('Invalid email'),
password: z.string().min(8, 'Must be at least 8 characters')
emailZod: z.string().email('Invalid email'),
passwordZod: z.string().min(8, 'Must be at least 8 characters')
})
type Schema = z.output<typeof schema>
Expand All @@ -30,11 +30,11 @@ async function submit () {
:state="state"
@submit.prevent="submit"
>
<UFormGroup label="Email" name="email-zod">
<UFormGroup label="Email" name="emailZod">
<UInput v-model="state.email" />
</UFormGroup>

<UFormGroup label="Password" name="password-zod">
<UFormGroup label="Password" name="passwordZod">
<UInput v-model="state.password" type="password" />
</UFormGroup>

Expand Down
6 changes: 1 addition & 5 deletions docs/content/3.forms/10.form.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,7 @@ defineExpose({
</script>
<template>
<UForm
ref="form"
:model="model"
@validate="validateWithVuelidate"
>
<UForm ref="form" :model="model" :validate="validateWithVuelidate">
<slot />
</UForm>
</template>
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/components/forms/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export default defineComponent({
`Form validation failed: ${JSON.stringify(errors.value, null, 2)}`
)
}

return props.state
}

expose({
Expand Down

1 comment on commit 248b0a6

@vercel
Copy link

@vercel vercel bot commented on 248b0a6 Aug 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ui – ./

ui-git-dev-nuxtlabs.vercel.app
ui-nuxtlabs.vercel.app
ui.nuxtlabs.com

Please sign in to comment.