mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 12:14:41 +01:00
feat(Form): handle multiple paths in validate (#1273)
This commit is contained in:
@@ -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)"}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user