Skip to content

Commit 56d8241

Browse files
committed
Improve navigating to components with partially matching errors
1 parent 994358f commit 56d8241

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

packages/admin/src/components/DitoSchema.vue

+24-18
Original file line numberDiff line numberDiff line change
@@ -598,26 +598,32 @@ export default DitoComponent.component('DitoSchema', {
598598
while (dataPathParts.length > 0) {
599599
const components = this.getComponentsByDataPath(dataPathParts)
600600
for (const component of components) {
601-
if (
602-
await component.navigateToComponent?.(
603-
fullDataPath,
604-
subComponents => {
605-
let found = false
606-
for (const component of subComponents) {
607-
const errs = errors[component.dataPath]
608-
if (
609-
errs &&
610-
component.showValidationErrors(errs, first && focus)
611-
) {
612-
found = true
613-
first = false
614-
break
615-
}
601+
const navigated = await component.navigateToComponent?.(
602+
fullDataPath,
603+
subComponents => {
604+
let found = false
605+
for (const component of subComponents) {
606+
const matched = Object.fromEntries(
607+
Object.entries(errors).filter(
608+
([dataPath]) =>
609+
normalizeDataPath(dataPath).startsWith(
610+
component.dataPath
611+
)
612+
)
613+
)
614+
if (
615+
Object.keys(matched).length > 0 &&
616+
component.showValidationErrors(matched, first && focus)
617+
) {
618+
found = true
619+
first = false
620+
break
616621
}
617-
return found
618622
}
619-
)
620-
) {
623+
return found
624+
}
625+
)
626+
if (navigated) {
621627
// Found a nested form to display at least parts fo the errors.
622628
// We can't show all errors at once, so we're done. Don't call
623629
// `notifyErrors()` yet, as we can only display it once

packages/admin/src/mixins/SourceMixin.js

+1
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ export default {
587587
this.$nextTick(callOnComplete)
588588
})
589589
}
590+
return
590591
}
591592
// Keep removing the last part until we find a match.
592593
dataPathParts.pop()

packages/admin/src/mixins/ValidationMixin.js

+3
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ export default {
9595
showValidationErrors(errors, focus) {
9696
// Convert from AJV errors objects to an array of error messages
9797
this.errors = []
98+
if (errors.length === 0) {
99+
return false
100+
}
98101
for (const { message } of errors) {
99102
this.addError(message, true)
100103
}

0 commit comments

Comments
 (0)