rename server validation binder

This commit is contained in:
Niels Lyngsø
2024-08-07 11:15:45 +02:00
parent 3f7b9ed74b
commit 1e5dd1c010
3 changed files with 11 additions and 5 deletions

View File

@@ -5,7 +5,7 @@ import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registr
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
import {
UmbBindValidationMessageToFormControl,
UmbBindServerValidationToFormControl,
UmbFormControlValidator,
UmbObserveValidationStateController,
} from '@umbraco-cms/backoffice/validation';
@@ -172,7 +172,7 @@ export class UmbPropertyElement extends UmbLitElement {
#propertyContext = new UmbPropertyContext(this);
#controlValidator?: UmbFormControlValidator;
#validationMessageBinder?: UmbBindValidationMessageToFormControl;
#validationMessageBinder?: UmbBindServerValidationToFormControl;
#valueObserver?: UmbObserverController<unknown>;
#configObserver?: UmbObserverController<UmbPropertyEditorConfigCollection | undefined>;
@@ -308,7 +308,7 @@ export class UmbPropertyElement extends UmbLitElement {
this.#controlValidator = new UmbFormControlValidator(this, this._element as any, this.#dataPath);
// We trust blindly that the dataPath is available at this stage. [NL]
if (this.#dataPath) {
this.#validationMessageBinder = new UmbBindValidationMessageToFormControl(
this.#validationMessageBinder = new UmbBindServerValidationToFormControl(
this,
this._element as any,
this.#dataPath,

View File

@@ -8,7 +8,11 @@ import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
const ctrlSymbol = Symbol();
const observeSymbol = Symbol();
export class UmbBindValidationMessageToFormControl extends UmbControllerBase {
/**
* Binds server validation to a form control.
* This controller will add a custom error to the form control if the validation context has any messages for the specified data path.
*/
export class UmbBindServerValidationToFormControl extends UmbControllerBase {
#context?: typeof UMB_VALIDATION_CONTEXT.TYPE;
#control: UmbFormControlMixinInterface<unknown>;
@@ -26,6 +30,7 @@ export class UmbBindValidationMessageToFormControl extends UmbControllerBase {
// If not valid lets see if we should remove server validation [NL]
if (!jsonStringComparison(this.#value, value)) {
this.#value = value;
console.log('remove messages');
// Only remove server validations from validation context [NL]
this.#messages.forEach((message) => {
if (message.type === 'server') {
@@ -46,6 +51,7 @@ export class UmbBindValidationMessageToFormControl extends UmbControllerBase {
context.messages.messagesOfTypeAndPath('server', dataPath),
(messages) => {
this.#messages = messages;
console.log('messages', messages);
this.#isValid = messages.length === 0;
if (!this.#isValid) {
this.#setup();

View File

@@ -1,3 +1,3 @@
export * from './bind-validation-message-to-form-control.controller.js';
export * from './bind-server-validation-to-form-control.controller.js';
export * from './observe-validation-state.controller.js';
export * from './form-control-validator.controller.js';