-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Form): handle
@error
event (#718)
Co-authored-by: Albert <albert@Alberts-MacBook-Pro.local> Co-authored-by: Romain Hamel <romain@boilr.io> Co-authored-by: Benjamin Canac <canacb1@gmail.com>
- Loading branch information
1 parent
1df07e2
commit e16379f
Showing
12 changed files
with
142 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<script setup lang="ts"> | ||
import type { FormError, FormErrorEvent, FormSubmitEvent } from '#ui/types' | ||
const state = reactive({ | ||
email: undefined, | ||
password: undefined | ||
}) | ||
const validate = (state: any): FormError[] => { | ||
const errors = [] | ||
if (!state.email) errors.push({ path: 'email', message: 'Required' }) | ||
if (!state.password) errors.push({ path: 'password', message: 'Required' }) | ||
return errors | ||
} | ||
async function onSubmit (event: FormSubmitEvent<any>) { | ||
// Do something with data | ||
console.log(event.data) | ||
} | ||
async function onError (event: FormErrorEvent) { | ||
const element = document.getElementById(event.errors[0].id) | ||
element?.focus() | ||
element?.scrollIntoView({ behavior: 'smooth', block: 'center' }) | ||
} | ||
</script> | ||
|
||
<template> | ||
<UForm :validate="validate" :state="state" @submit="onSubmit" @error="onError"> | ||
<UFormGroup label="Email" name="email"> | ||
<UInput v-model="state.email" /> | ||
</UFormGroup> | ||
|
||
<UFormGroup label="Password" name="password"> | ||
<UInput v-model="state.password" type="password" /> | ||
</UFormGroup> | ||
|
||
<UButton type="submit"> | ||
Submit | ||
</UButton> | ||
</UForm> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
e16379f
There was a problem hiding this comment.
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-nuxt-js.vercel.app
ui-git-dev-nuxt-js.vercel.app
ui.nuxt.com