validate document-type
This commit is contained in:
@@ -1,19 +1,24 @@
|
||||
import { css, customElement, html, property, state } from '@umbraco-cms/backoffice/external/lit';
|
||||
import { type PropertyValueMap, css, customElement, html, property, state } from '@umbraco-cms/backoffice/external/lit';
|
||||
import { generateAlias } from '@umbraco-cms/backoffice/utils';
|
||||
import { UmbChangeEvent } from '@umbraco-cms/backoffice/event';
|
||||
import { UmbFormControlMixin } from '@umbraco-cms/backoffice/validation';
|
||||
import { UMB_VALIDATION_EMPTY_LOCALIZATION_KEY, UmbFormControlMixin } from '@umbraco-cms/backoffice/validation';
|
||||
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
|
||||
import { UUIInputEvent } from '@umbraco-cms/backoffice/external/uui';
|
||||
import type { UUIInputElement } from '@umbraco-cms/backoffice/external/uui';
|
||||
|
||||
@customElement('umb-input-with-alias')
|
||||
export class UmbInputWithAliasElement extends UmbFormControlMixin<string, typeof UmbLitElement>(UmbLitElement) {
|
||||
export class UmbInputWithAliasElement extends UmbFormControlMixin<string, typeof UmbLitElement, undefined>(
|
||||
UmbLitElement,
|
||||
) {
|
||||
@property({ type: String })
|
||||
label: string = '';
|
||||
|
||||
@property({ type: String, reflect: false })
|
||||
alias?: string;
|
||||
|
||||
@property({ type: Boolean, reflect: true })
|
||||
required: boolean = false;
|
||||
|
||||
@property({ type: Boolean, reflect: true, attribute: 'alias-readonly' })
|
||||
aliasReadonly = false;
|
||||
|
||||
@@ -23,7 +28,15 @@ export class UmbInputWithAliasElement extends UmbFormControlMixin<string, typeof
|
||||
@state()
|
||||
private _aliasLocked = true;
|
||||
|
||||
override firstUpdated() {
|
||||
protected override firstUpdated(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void {
|
||||
super.firstUpdated(_changedProperties);
|
||||
|
||||
this.addValidator(
|
||||
'valueMissing',
|
||||
() => UMB_VALIDATION_EMPTY_LOCALIZATION_KEY,
|
||||
() => this.required && !this.value,
|
||||
);
|
||||
|
||||
this.shadowRoot?.querySelectorAll<UUIInputElement>('uui-input').forEach((x) => this.addFormControlElement(x));
|
||||
}
|
||||
|
||||
@@ -64,6 +77,13 @@ export class UmbInputWithAliasElement extends UmbFormControlMixin<string, typeof
|
||||
this.dispatchEvent(new UmbChangeEvent());
|
||||
}
|
||||
}
|
||||
#onAliasBlur() {
|
||||
// If the alias is empty, then try to generate one [NL]
|
||||
if (!this.alias && this._aliasLocked === false) {
|
||||
this.alias = generateAlias(this.value ?? '');
|
||||
this.dispatchEvent(new UmbChangeEvent());
|
||||
}
|
||||
}
|
||||
|
||||
#onToggleAliasLock(event: CustomEvent) {
|
||||
this._aliasLocked = !this._aliasLocked;
|
||||
@@ -82,7 +102,8 @@ export class UmbInputWithAliasElement extends UmbFormControlMixin<string, typeof
|
||||
placeholder=${nameLabel}
|
||||
label=${nameLabel}
|
||||
.value=${this.value}
|
||||
@input=${this.#onNameChange}>
|
||||
@input=${this.#onNameChange}
|
||||
?required=${this.required}>
|
||||
<uui-input-lock
|
||||
auto-width
|
||||
name="alias"
|
||||
@@ -92,7 +113,9 @@ export class UmbInputWithAliasElement extends UmbFormControlMixin<string, typeof
|
||||
.value=${this.alias}
|
||||
?locked=${this._aliasLocked && !this.aliasReadonly}
|
||||
?readonly=${this.aliasReadonly}
|
||||
?required=${this.required}
|
||||
@input=${this.#onAliasChange}
|
||||
@blur=${this.#onAliasBlur}
|
||||
@lock-change=${this.#onToggleAliasLock}>
|
||||
</uui-input-lock>
|
||||
</uui-input>
|
||||
|
||||
@@ -112,12 +112,14 @@ export class UmbContentTypeStructureManager<
|
||||
if (!contentType || !contentType.unique) throw new Error('Could not find the Content Type to save');
|
||||
|
||||
const { error, data } = await this.#repository.save(contentType);
|
||||
if (error || !data) return { error, data };
|
||||
if (error || !data) {
|
||||
throw error?.message ?? 'Repository did not return data after save.';
|
||||
}
|
||||
|
||||
// Update state with latest version:
|
||||
this.#contentTypes.updateOne(contentType.unique, data);
|
||||
|
||||
return { error, data };
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -72,7 +72,7 @@ export class UmbInputDataTypeElement extends UmbFormControlMixin(UmbLitElement,
|
||||
this.addValidator(
|
||||
'valueMissing',
|
||||
() => UMB_VALIDATION_EMPTY_LOCALIZATION_KEY,
|
||||
() => this.hasAttribute('required') && this.value === '',
|
||||
() => this.hasAttribute('required') && !this.value,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import { umbFocus, UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
|
||||
import { css, html, customElement, state, ifDefined } from '@umbraco-cms/backoffice/external/lit';
|
||||
import { UMB_MODAL_MANAGER_CONTEXT, UMB_ICON_PICKER_MODAL } from '@umbraco-cms/backoffice/modal';
|
||||
import type { UUITextareaElement } from '@umbraco-cms/backoffice/external/uui';
|
||||
import { umbBindToValidation } from '@umbraco-cms/backoffice/validation';
|
||||
|
||||
@customElement('umb-document-type-workspace-editor')
|
||||
export class UmbDocumentTypeWorkspaceEditorElement extends UmbLitElement {
|
||||
@@ -86,10 +87,12 @@ export class UmbDocumentTypeWorkspaceEditorElement extends UmbLitElement {
|
||||
<umb-input-with-alias
|
||||
id="name"
|
||||
label=${this.localize.term('placeholders_entername')}
|
||||
value=${this._name}
|
||||
alias=${this._alias}
|
||||
.value=${this._name}
|
||||
.alias=${this._alias}
|
||||
?auto-generate-alias=${this._isNew}
|
||||
@change="${this.#onNameAndAliasChange}"
|
||||
required
|
||||
${umbBindToValidation(this, '$.name', this._name)}
|
||||
${umbFocus()}>
|
||||
</umb-input-with-alias>
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import type { UmbReferenceByUnique } from '@umbraco-cms/backoffice/models';
|
||||
import type { UmbRoutableWorkspaceContext } from '@umbraco-cms/backoffice/workspace';
|
||||
import type { UmbPathPatternTypeAsEncodedParamsType } from '@umbraco-cms/backoffice/router';
|
||||
import { UmbValidationContext } from '@umbraco-cms/backoffice/validation';
|
||||
|
||||
type EntityType = UmbDocumentTypeDetailModel;
|
||||
export class UmbDocumentTypeWorkspaceContext
|
||||
@@ -79,6 +80,8 @@ export class UmbDocumentTypeWorkspaceContext
|
||||
constructor(host: UmbControllerHost) {
|
||||
super(host, 'Umb.Workspace.DocumentType');
|
||||
|
||||
this.addValidationContext(new UmbValidationContext(this).provide());
|
||||
|
||||
// General for content types:
|
||||
//this.data = this.structure.ownerContentType;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user