rename message prop to body
This commit is contained in:
@@ -8,7 +8,7 @@ export interface UmbValidationMessage {
|
||||
type: UmbValidationMessageType;
|
||||
key: string;
|
||||
path: string;
|
||||
message: string;
|
||||
body: string;
|
||||
}
|
||||
|
||||
export class UmbValidationMessagesManager {
|
||||
@@ -72,24 +72,23 @@ export class UmbValidationMessagesManager {
|
||||
);
|
||||
}
|
||||
|
||||
addMessage(type: UmbValidationMessageType, path: string, message: string, key: string = UmbId.new()): void {
|
||||
addMessage(type: UmbValidationMessageType, path: string, body: string, key: string = UmbId.new()): void {
|
||||
path = this.#translatePath(path) ?? path;
|
||||
// check if there is an existing message with the same path and type, and append the new messages: [NL]
|
||||
if (this.#messages.getValue().find((x) => x.type === type && x.path === path && x.message === message)) {
|
||||
if (this.#messages.getValue().find((x) => x.type === type && x.path === path && x.body === body)) {
|
||||
return;
|
||||
}
|
||||
this.#messages.appendOne({ type, key, path, message });
|
||||
this.#messages.appendOne({ type, key, path, body: body });
|
||||
}
|
||||
|
||||
addMessages(type: UmbValidationMessageType, path: string, messages: Array<string>): void {
|
||||
addMessages(type: UmbValidationMessageType, path: string, bodies: Array<string>): void {
|
||||
path = this.#translatePath(path) ?? path;
|
||||
// filter out existing messages with the same path and type, and append the new messages: [NL]
|
||||
const existingMessages = this.#messages.getValue();
|
||||
const newMessages = messages.filter(
|
||||
(message) =>
|
||||
existingMessages.find((x) => x.type === type && x.path === path && x.message === message) === undefined,
|
||||
const newBodies = bodies.filter(
|
||||
(message) => existingMessages.find((x) => x.type === type && x.path === path && x.body === message) === undefined,
|
||||
);
|
||||
this.#messages.append(newMessages.map((message) => ({ type, key: UmbId.new(), path, message })));
|
||||
this.#messages.append(newBodies.map((body) => ({ type, key: UmbId.new(), path, body })));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -109,7 +109,7 @@ export class UmbValidationContext extends UmbControllerBase implements UmbValida
|
||||
// TODO: Subtract the base path from the path, so it becomes local to this context:
|
||||
const path = ReplaceStartOfString(msg.path, this.#baseDataPath!, '$');
|
||||
// Notice, the local message uses the same key. [NL]
|
||||
this.messages.addMessage(msg.type, path, msg.message, msg.key);
|
||||
this.messages.addMessage(msg.type, path, msg.body, msg.key);
|
||||
});
|
||||
},
|
||||
'observeParentMessages',
|
||||
@@ -133,7 +133,7 @@ export class UmbValidationContext extends UmbControllerBase implements UmbValida
|
||||
// replace this.#baseDataPath (if it starts with it) with $ in the path, so it becomes relative to the parent context
|
||||
const path = ReplaceStartOfString(msg.path, '$', this.#baseDataPath!);
|
||||
// Notice, the parent message uses the same key. [NL]
|
||||
this.#parent!.messages.addMessage(msg.type, path, msg.message, msg.key);
|
||||
this.#parent!.messages.addMessage(msg.type, path, msg.body, msg.key);
|
||||
});
|
||||
},
|
||||
'observeLocalMessages',
|
||||
|
||||
@@ -66,7 +66,7 @@ export class UmbBindServerValidationToFormControl extends UmbControllerBase {
|
||||
if (!this.#controlValidator) {
|
||||
this.#controlValidator = this.#control.addValidator(
|
||||
'customError',
|
||||
() => this.#messages.map((x) => x.message).join(', '),
|
||||
() => this.#messages.map((x) => x.body).join(', '),
|
||||
() => !this.#isValid,
|
||||
);
|
||||
//this.#control.addEventListener('change', this.#onControlChange);
|
||||
|
||||
Reference in New Issue
Block a user