communicate with console error if it fails
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user