Skip to content

Commit

Permalink
feat(Form): handle multiple paths in validate (#1273)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonySendra authored Jan 27, 2024
1 parent 2e1ef55 commit 20ac4b3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/content/3.forms/10.form.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ When accessing the component via a template ref, you can use the following:
::field{name="submit ()" type="Promise<void>"}
Triggers form submission.
::
::field{name="validate (path?: string, opts: { silent?: boolean })" type="Promise<T>"}
::field{name="validate (path?: string | string[], opts: { silent?: boolean })" type="Promise<T>"}
Triggers form validation. Will raise any errors unless `opts.silent` is set to true.
::
::field{name="clear (path?: string)"}
Expand Down
14 changes: 10 additions & 4 deletions src/runtime/components/forms/Form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,19 @@ export default defineComponent({
return errs
}
async function validate (path?: string, opts: { silent?: boolean } = { silent: false }) {
if (path) {
async function validate (path?: string | string[], opts: { silent?: boolean } = { silent: false }) {
let paths = path
if (path && !Array.isArray(path)) {
paths = [path]
}
if (paths) {
const otherErrors = errors.value.filter(
(error) => error.path !== path
(error) => !paths.includes(error.path)
)
const pathErrors = (await getErrors()).filter(
(error) => error.path === path
(error) => paths.includes(error.path)
)
errors.value = otherErrors.concat(pathErrors)
} else {
Expand Down

1 comment on commit 20ac4b3

@vercel
Copy link

@vercel vercel bot commented on 20ac4b3 Jan 27, 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-git-dev-nuxt-js.vercel.app
ui.nuxt.com
ui-nuxt-js.vercel.app

Please sign in to comment.