communicate with console error if it fails

This commit is contained in:
Niels Lyngsø
2025-01-31 21:17:45 +01:00
parent 09072b6946
commit 2fe2b46670
2 changed files with 12 additions and 2 deletions

View File

@@ -131,6 +131,11 @@ export class UmbValidationController extends UmbControllerBase implements UmbVal
this.#parentMessages = msgs;
msgs.forEach((msg) => {
const path = ReplaceStartOfPath(msg.path, this.#baseDataPath!, '$');
if (path === undefined) {
throw new Error(
'Path was not transformed correctly and can therefor not be transfered to the local validation context messages.',
);
}
// Notice, the local message uses the same key. [NL]
this.messages.addMessage(msg.type, path, msg.body, msg.key);
});
@@ -152,6 +157,11 @@ export class UmbValidationController extends UmbControllerBase implements UmbVal
msgs.forEach((msg) => {
// replace this.#baseDataPath (if it starts with it) with $ in the path, so it becomes relative to the parent context
const path = ReplaceStartOfPath(msg.path, '$', this.#baseDataPath!);
if (path === undefined) {
throw new Error(
'Path was not transformed correctly and can therefor not be synced with parent messages.',
);
}
// Notice, the parent message uses the same key. [NL]
this.#parent!.messages.addMessage(msg.type, path, msg.body, msg.key);
});

View File

@@ -5,10 +5,10 @@
* @param startTo {string}
* @returns {string}
*/
export function ReplaceStartOfPath(path: string, startFrom: string, startTo: string): string {
export function ReplaceStartOfPath(path: string, startFrom: string, startTo: string): string | undefined {
// if the path conitnues with a . or [ aftr startFrom, then replace it with startTo, otherwise if identical then it is also a match. [NL]
if (path.startsWith(startFrom + '.') || path === startFrom) {
return startTo + path.slice(startFrom.length);
}
return path;
return;
}