data path state in property context
This commit is contained in:
@@ -43,9 +43,13 @@ export class UmbPropertyContext<ValueType = any> extends UmbContextBase<UmbPrope
|
||||
|
||||
#validation = new UmbObjectState<UmbPropertyTypeValidationModel | undefined>(undefined);
|
||||
public readonly validation = this.#validation.asObservable();
|
||||
|
||||
public readonly validationMandatory = this.#validation.asObservablePart((x) => x?.mandatory);
|
||||
public readonly validationMandatoryMessage = this.#validation.asObservablePart((x) => x?.mandatoryMessage);
|
||||
|
||||
#dataPath = new UmbStringState(undefined);
|
||||
public readonly dataPath = this.#dataPath.asObservable();
|
||||
|
||||
#editor = new UmbBasicState<UmbPropertyEditorUiElement | undefined>(undefined);
|
||||
public readonly editor = this.#editor.asObservable();
|
||||
|
||||
@@ -206,6 +210,13 @@ export class UmbPropertyContext<ValueType = any> extends UmbContextBase<UmbPrope
|
||||
return this.#validation.getValue();
|
||||
}
|
||||
|
||||
public setDataPath(dataPath: string | undefined): void {
|
||||
this.#dataPath.setValue(dataPath);
|
||||
}
|
||||
public getDataPath(): string | undefined {
|
||||
return this.#dataPath.getValue();
|
||||
}
|
||||
|
||||
public resetValue(): void {
|
||||
this.setValue(undefined); // TODO: We should get the value from the server aka. the value from the persisted data. (Most workspaces holds this data, via dataset) [NL]
|
||||
}
|
||||
|
||||
@@ -135,15 +135,14 @@ export class UmbPropertyElement extends UmbLitElement {
|
||||
*/
|
||||
@property({ type: String, attribute: 'data-path' })
|
||||
public set dataPath(dataPath: string | undefined) {
|
||||
this.#dataPath = dataPath;
|
||||
this.#propertyContext.setDataPath(dataPath);
|
||||
new UmbObserveValidationStateController(this, dataPath, (invalid) => {
|
||||
this._invalid = invalid;
|
||||
});
|
||||
}
|
||||
public get dataPath(): string | undefined {
|
||||
return this.#dataPath;
|
||||
return this.#propertyContext.getDataPath();
|
||||
}
|
||||
#dataPath?: string;
|
||||
|
||||
@state()
|
||||
private _variantDifference?: string;
|
||||
@@ -319,13 +318,14 @@ export class UmbPropertyElement extends UmbLitElement {
|
||||
);
|
||||
|
||||
if ('checkValidity' in this._element) {
|
||||
this.#controlValidator = new UmbFormControlValidator(this, this._element as any, this.#dataPath);
|
||||
const dataPath = this.dataPath;
|
||||
this.#controlValidator = new UmbFormControlValidator(this, this._element as any, dataPath);
|
||||
// We trust blindly that the dataPath is available at this stage. [NL]
|
||||
if (this.#dataPath) {
|
||||
if (dataPath) {
|
||||
this.#validationMessageBinder = new UmbBindServerValidationToFormControl(
|
||||
this,
|
||||
this._element as any,
|
||||
this.#dataPath,
|
||||
dataPath,
|
||||
);
|
||||
this.#validationMessageBinder.value = this.#propertyContext.getValue();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user