Merge pull request #18092 from umbraco/v15/feature/reject-validation-promise
Feature: Clean up validation messages
This commit is contained in:
@@ -24,6 +24,7 @@ export class UmbServerModelValidatorContext
|
||||
{
|
||||
#validatePromise?: Promise<void>;
|
||||
#validatePromiseResolve?: () => void;
|
||||
#validatePromiseReject?: () => void;
|
||||
|
||||
#context?: typeof UMB_VALIDATION_CONTEXT.TYPE;
|
||||
#isValid = true;
|
||||
@@ -50,9 +51,10 @@ export class UmbServerModelValidatorContext
|
||||
this.#context?.messages.removeMessagesByType('server');
|
||||
|
||||
this.#isValid = false;
|
||||
//this.#validatePromiseReject?.();
|
||||
this.#validatePromise = new Promise<void>((resolve) => {
|
||||
this.#validatePromiseReject?.();
|
||||
this.#validatePromise = new Promise<void>((resolve, reject) => {
|
||||
this.#validatePromiseResolve = resolve;
|
||||
this.#validatePromiseReject = reject;
|
||||
});
|
||||
|
||||
// Store this state of the data for translator look ups:
|
||||
@@ -100,6 +102,7 @@ export class UmbServerModelValidatorContext
|
||||
|
||||
this.#validatePromiseResolve?.();
|
||||
this.#validatePromiseResolve = undefined;
|
||||
this.#validatePromiseReject = undefined;
|
||||
}
|
||||
|
||||
get isValid(): boolean {
|
||||
@@ -112,7 +115,12 @@ export class UmbServerModelValidatorContext
|
||||
return this.#isValid ? Promise.resolve() : Promise.reject();
|
||||
}
|
||||
|
||||
reset(): void {}
|
||||
reset(): void {
|
||||
this.#isValid = true;
|
||||
this.#validatePromiseReject?.();
|
||||
this.#validatePromiseResolve = undefined;
|
||||
this.#validatePromiseReject = undefined;
|
||||
}
|
||||
|
||||
focusFirstInvalidElement(): void {}
|
||||
|
||||
|
||||
@@ -192,6 +192,9 @@ export class UmbValidationController extends UmbControllerBase implements UmbVal
|
||||
*/
|
||||
addValidator(validator: UmbValidator): void {
|
||||
if (this.#validators.includes(validator)) return;
|
||||
if (validator === this) {
|
||||
throw new Error('Cannot add it self as validator');
|
||||
}
|
||||
this.#validators.push(validator);
|
||||
//validator.addEventListener('change', this.#onValidatorChange);
|
||||
if (this.#validationMode) {
|
||||
@@ -231,7 +234,7 @@ export class UmbValidationController extends UmbControllerBase implements UmbVal
|
||||
|
||||
if (!this.messages) {
|
||||
// This Context has been destroyed while is was validating, so we should not continue.
|
||||
return;
|
||||
return Promise.reject();
|
||||
}
|
||||
|
||||
// If we have any messages then we are not valid, otherwise lets check the validation results: [NL]
|
||||
@@ -264,6 +267,7 @@ export class UmbValidationController extends UmbControllerBase implements UmbVal
|
||||
*/
|
||||
reset(): void {
|
||||
this.#validationMode = false;
|
||||
this.messages.clear();
|
||||
this.#validators.forEach((v) => v.reset());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user