Skip to content

Commit

Permalink
feat(Form): expose submit function (#1186)
Browse files Browse the repository at this point in the history
  • Loading branch information
romhml committed Jan 2, 2024
1 parent d64cb8a commit 4a25a12
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion docs/content/3.forms/10.form.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ componentProps:
## API

::field-group
::field{name="submit ()" type="Promise<void>"}
Triggers form submission.
::
::field{name="validate (path?: string, opts: { silent?: boolean })" type="Promise<T>"}
Triggers form validation. Will raise any errors unless `opts.silent` is set to true.
::
Expand All @@ -217,5 +220,5 @@ componentProps:
::
::field{name="errors" type="Ref<FormError[]>"}
A reference to the array containing validation errors. Use this to access or manipulate the error information.
::
::
::
3 changes: 3 additions & 0 deletions src/runtime/components/forms/Form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ export default defineComponent({
errors.value = errs
}
},
async submit () {
await onSubmit(new Event('submit'))
},
getErrors (path?: string) {
if (path) {
return errors.value.filter((err) => err.path === path)
Expand Down
1 change: 1 addition & 0 deletions src/runtime/types/form.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface Form<T> {
errors: Ref<FormError[]>
setErrors(errs: FormError[], path?: string): void
getErrors(path?: string): FormError[]
submit(): Promise<void>
}

export type FormSubmitEvent<T> = SubmitEvent & { data: T }
Expand Down

1 comment on commit 4a25a12

@vercel
Copy link

@vercel vercel bot commented on 4a25a12 Jan 2, 2024

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

Please sign in to comment.