Skip to content

Commit 2dd2329

Browse files
authored
Resolve seen issue regarding destroyed validation context (#19359)
maybe messages has been destroyed so enable it to be undefined
1 parent 57bec51 commit 2dd2329

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

src/Umbraco.Web.UI.Client/src/packages/core/validation/controllers/bind-server-validation-to-form-control.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class UmbBindServerValidationToFormControl extends UmbControllerBase {
3131
this.#value = value;
3232
// Only remove server validations from validation context [NL]
3333
const toRemove = this.#messages.filter((x) => x.type === 'server').map((msg) => msg.key);
34-
this.#context?.messages.removeMessageByKeys(toRemove);
34+
this.#context?.messages?.removeMessageByKeys(toRemove);
3535
}
3636
}
3737
}

src/Umbraco.Web.UI.Client/src/packages/core/validation/controllers/form-control-validator.controller.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class UmbFormControlValidator extends UmbControllerBase implements UmbVal
3030
this.#context = context;
3131
context?.addValidator(this);
3232
// If we have a message already, then un-pristine the control:
33-
if (dataPath && context?.messages.getHasMessagesOfPathAndDescendant(dataPath)) {
33+
if (dataPath && context?.messages?.getHasMessagesOfPathAndDescendant(dataPath)) {
3434
formControl.pristine = false;
3535
}
3636
});
@@ -46,11 +46,11 @@ export class UmbFormControlValidator extends UmbControllerBase implements UmbVal
4646

4747
if (this.#dataPath) {
4848
if (newVal) {
49-
this.#context?.messages.removeMessagesByTypeAndPath('client', this.#dataPath);
49+
this.#context?.messages?.removeMessagesByTypeAndPath('client', this.#dataPath);
5050
} else {
5151
// We only want to add the message if it is not already there. (this could be a custom or server message that got binded to the control, we do not want that double.)
52-
if (!this.#context?.messages.getHasMessageOfPathAndBody(this.#dataPath, this.#control.validationMessage)) {
53-
this.#context?.messages.addMessage('client', this.#dataPath, this.#control.validationMessage);
52+
if (!this.#context?.messages?.getHasMessageOfPathAndBody(this.#dataPath, this.#control.validationMessage)) {
53+
this.#context?.messages?.addMessage('client', this.#dataPath, this.#control.validationMessage);
5454
}
5555
}
5656
}

src/Umbraco.Web.UI.Client/src/packages/core/validation/controllers/validation.controller.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class UmbValidationController extends UmbControllerBase implements UmbVal
2727
>;
2828
#inUnprovidingState: boolean = false;
2929

30-
// @reprecated - Will be removed in v.17
30+
// @deprecated - Will be removed in v.17
3131
// Local version of the data send to the server, only use-case is for translation.
3232
#translationData = new UmbObjectState<any>(undefined);
3333
/**
@@ -81,7 +81,7 @@ export class UmbValidationController extends UmbControllerBase implements UmbVal
8181
setVariantId(variantId: UmbVariantId): void {
8282
this.#variantId = variantId;
8383
// @.culture == null && @.segment == null
84-
this.messages.filter((msg) => {
84+
this.messages?.filter((msg) => {
8585
// Figure out how many times '@.culture ==' is present in the path:
8686
//const cultureMatches = (msg.path.match(/@\.culture ==/g) || []);
8787
// I like a Regex that finds all the @.culture == and @.segment == in the path. they are adjacent. and I like to know the value following '== '
@@ -113,7 +113,7 @@ export class UmbValidationController extends UmbControllerBase implements UmbVal
113113
* @param translator
114114
*/
115115
async addTranslator(translator: UmbValidationMessageTranslator) {
116-
this.messages.addTranslator(translator);
116+
this.messages?.addTranslator(translator);
117117
}
118118

119119
/**

0 commit comments

Comments
 (0)