Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Form): return state on validate #472

Merged
merged 4 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions docs/components/content/examples/FormExampleJoi.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ async function submit () {
:state="state"
@submit.prevent="submit"
>
<UFormGroup label="Email" name="email-joi">
Copy link
Member

Choose a reason for hiding this comment

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

Indeed, I see the issue. I've updated this because it throws some duplicate ids warnings in the console.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok! Let's update the schema path then!

Copy link
Collaborator Author

@romhml romhml Aug 1, 2023

Choose a reason for hiding this comment

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

I looked into it, is it necessary to bind the name props to id on inputs?
https://github.com/nuxtlabs/ui/blob/dev/src/runtime/components/forms/Input.vue#L4

Copy link
Member

@benjamincanac benjamincanac Aug 1, 2023

Choose a reason for hiding this comment

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

Not really, it was just a shortcut to write less code. But removing it would cause a breaking change though.

Copy link
Member

Choose a reason for hiding this comment

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

Oh sorry, the id is here to be targeted by the FormGroup component through <label for="..." />, we can't remove it..

Copy link
Member

Choose a reason for hiding this comment

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

What can we do to fix this quickly? I plan to release the 2.7.0 today.

Copy link
Collaborator Author

@romhml romhml Aug 1, 2023

Choose a reason for hiding this comment

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

I changed the name attributes in the examples, should be good enough for now

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh sorry, the id is here to be targeted by the FormGroup component through , we can't remove it..

Could you send me a link to the code?

Copy link
Member

Choose a reason for hiding this comment

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

<UFormGroup label="Email" name="email">
<UInput v-model="state.email" />
</UFormGroup>

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

Expand Down
4 changes: 2 additions & 2 deletions docs/components/content/examples/FormExampleYup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ async function submit () {
:state="state"
@submit.prevent="submit"
>
<UFormGroup label="Email" name="email-yup">
<UFormGroup label="Email" name="email">
<UInput v-model="state.email" />
</UFormGroup>

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

Expand Down
4 changes: 2 additions & 2 deletions docs/components/content/examples/FormExampleZod.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ async function submit () {
:state="state"
@submit.prevent="submit"
>
<UFormGroup label="Email" name="email-zod">
<UFormGroup label="Email" name="email">
<UInput v-model="state.email" />
</UFormGroup>

<UFormGroup label="Password" name="password-zod">
<UFormGroup label="Password" name="password">
<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