diff --git a/docs/content/3.forms/10.form.md b/docs/content/3.forms/10.form.md index 121bd9f6..cb92d2c9 100644 --- a/docs/content/3.forms/10.form.md +++ b/docs/content/3.forms/10.form.md @@ -208,7 +208,7 @@ When accessing the component via a template ref, you can use the following: ::field{name="submit ()" type="Promise"} Triggers form submission. :: - ::field{name="validate (path?: string, opts: { silent?: boolean })" type="Promise"} + ::field{name="validate (path?: string | string[], opts: { silent?: boolean })" type="Promise"} Triggers form validation. Will raise any errors unless `opts.silent` is set to true. :: ::field{name="clear (path?: string)"} diff --git a/src/runtime/components/forms/Form.vue b/src/runtime/components/forms/Form.vue index 414a60a8..25b4df5f 100644 --- a/src/runtime/components/forms/Form.vue +++ b/src/runtime/components/forms/Form.vue @@ -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 {