Skip to content

Commit cfc5831

Browse files
committed
Sets the context's validation
and `mandatory` attribute on the `umb-property-layout`.
1 parent 25292c8 commit cfc5831

File tree

1 file changed

+43
-13
lines changed

1 file changed

+43
-13
lines changed

src/packages/core/property/property/property.element.ts

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
import { UmbPropertyContext } from './property.context.js';
2-
import type { ManifestPropertyEditorUi } from '@umbraco-cms/backoffice/extension-registry';
3-
import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry';
4-
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
5-
import { css, html, customElement, property, state, nothing } from '@umbraco-cms/backoffice/external/lit';
2+
import { css, customElement, html, property, state, nothing } from '@umbraco-cms/backoffice/external/lit';
63
import { createExtensionElement } from '@umbraco-cms/backoffice/extension-api';
7-
import type { UmbObserverController } from '@umbraco-cms/backoffice/observable-api';
4+
import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry';
85
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
9-
import type {
10-
UmbPropertyEditorConfigCollection,
11-
UmbPropertyEditorConfig,
12-
} from '@umbraco-cms/backoffice/property-editor';
6+
import { UmbTextStyles } from '@umbraco-cms/backoffice/style';
137
import {
148
UmbBindValidationMessageToFormControl,
159
UmbFormControlValidator,
1610
UmbObserveValidationStateController,
1711
} from '@umbraco-cms/backoffice/validation';
18-
import type { UmbPropertyTypeAppearanceModel } from '@umbraco-cms/backoffice/content-type';
12+
import type { ManifestPropertyEditorUi } from '@umbraco-cms/backoffice/extension-registry';
13+
import type {
14+
UmbPropertyEditorConfigCollection,
15+
UmbPropertyEditorConfig,
16+
} from '@umbraco-cms/backoffice/property-editor';
17+
import type {
18+
UmbPropertyTypeAppearanceModel,
19+
UmbPropertyTypeValidationModel,
20+
} from '@umbraco-cms/backoffice/content-type';
21+
import type { UmbObserverController } from '@umbraco-cms/backoffice/observable-api';
1922

2023
/**
2124
* @element umb-property
@@ -112,6 +115,17 @@ export class UmbPropertyElement extends UmbLitElement {
112115
return this.#propertyContext.getConfig();
113116
}
114117

118+
/**
119+
* Validation: Validation settings for the property.
120+
*/
121+
@property({ type: Object, attribute: false })
122+
public set validation(validation: UmbPropertyTypeValidationModel | undefined) {
123+
this.#propertyContext.setValidation(validation);
124+
}
125+
public get validation() {
126+
return this.#propertyContext.getValidation();
127+
}
128+
115129
/**
116130
* DataPath, declare the path to the value of the data that this property represents.
117131
* @public
@@ -152,6 +166,9 @@ export class UmbPropertyElement extends UmbLitElement {
152166
@state()
153167
private _orientation: 'horizontal' | 'vertical' = 'horizontal';
154168

169+
@state()
170+
private _mandatory?: boolean;
171+
155172
#propertyContext = new UmbPropertyContext(this);
156173

157174
#controlValidator?: UmbFormControlValidator;
@@ -169,34 +186,46 @@ export class UmbPropertyElement extends UmbLitElement {
169186
},
170187
null,
171188
);
189+
172190
this.observe(
173191
this.#propertyContext.label,
174192
(label) => {
175193
this._label = label;
176194
},
177195
null,
178196
);
197+
179198
this.observe(
180199
this.#propertyContext.description,
181200
(description) => {
182201
this._description = description;
183202
},
184203
null,
185204
);
205+
186206
this.observe(
187207
this.#propertyContext.variantDifference,
188208
(variantDifference) => {
189209
this._variantDifference = variantDifference;
190210
},
191211
null,
192212
);
213+
193214
this.observe(
194215
this.#propertyContext.appearance,
195216
(appearance) => {
196217
this._orientation = appearance?.labelOnTop ? 'vertical' : 'horizontal';
197218
},
198219
null,
199220
);
221+
222+
this.observe(
223+
this.#propertyContext.validation,
224+
(validation) => {
225+
this._mandatory = validation?.mandatory;
226+
},
227+
null,
228+
);
200229
}
201230

202231
private _onPropertyEditorChange = (e: CustomEvent): void => {
@@ -297,10 +326,11 @@ export class UmbPropertyElement extends UmbLitElement {
297326
return html`
298327
<umb-property-layout
299328
id="layout"
300-
.alias=${this._alias}
301-
.label=${this._label}
302-
.description=${this._description}
329+
.alias=${this._alias ?? ''}
330+
.label=${this._label ?? ''}
331+
.description=${this._description ?? ''}
303332
.orientation=${this._orientation ?? 'horizontal'}
333+
?mandatory=${this._mandatory}
304334
?invalid=${this._invalid}>
305335
${this.#renderPropertyActionMenu()}
306336
${this._variantDifference

0 commit comments

Comments
 (0)