Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ export function getProperties(
"selectionMethod",
"selectAllButton",
"selectAllButtonCaption",
"onChangeEvent",
...ASSOCIATION_SOURCE_CONFIG
]);
if (values.optionsSourceDatabaseDataSource === null) {
Expand Down Expand Up @@ -140,8 +139,18 @@ export function getProperties(
if (values.customEditability !== "conditionally") {
hidePropertiesIn(defaultProperties, values, ["customEditabilityExpression"]);
}

// hide generic On change event when value is not saved anywhere.
// Users should use On change that is assigned to the selection API (onChangeDatabaseEvent)
hidePropertiesIn(defaultProperties, values, ["onChangeEvent"]);
} else {
hidePropertiesIn(defaultProperties, values, ["customEditability", "customEditabilityExpression"]);

// hide On change event that is tied to the selection API (onChangeDatabaseEvent)
// this event runs on initialization even though the actual value set to
// Target (databaseAttributeString) is not changing and this is confusing.
// Users should use generic On change event
hidePropertiesIn(defaultProperties, values, ["onChangeDatabaseEvent"]);
}
} else if (values.source === "static") {
hidePropertiesIn(defaultProperties, values, [
Expand Down
10 changes: 6 additions & 4 deletions packages/pluggableWidgets/combobox-web/src/Combobox.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@
<!-- END CAPTIONS -->
</propertyGroup>
<propertyGroup caption="Store value">
<property key="optionsSourceDatabaseValueAttribute" type="attribute" dataSource="optionsSourceDatabaseDataSource">
<caption>Value</caption>
<property key="databaseAttributeString" type="attribute" setLabel="true" required="false">
<caption>Target</caption>
<description />
<attributeTypes>
<attributeType name="String" />
Expand All @@ -114,8 +114,8 @@
<attributeType name="Enum" />
</attributeTypes>
</property>
<property key="databaseAttributeString" type="attribute" setLabel="true" required="false">
<caption>Target attribute</caption>
<property key="optionsSourceDatabaseValueAttribute" type="attribute" dataSource="optionsSourceDatabaseDataSource">
<caption>Value</caption>
<description />
<attributeTypes>
<attributeType name="String" />
Expand Down Expand Up @@ -314,10 +314,12 @@

<propertyGroup caption="Events">
<property key="onChangeEvent" type="action" required="false">
<!-- this event is called manually in the code, not attached to anything -->
<caption>On change</caption>
<description />
</property>
<property key="onChangeDatabaseEvent" type="action" required="false">
<!-- this event is tied to the Selection API property, fired automatically -->
<caption>On change</caption>
<description />
</property>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EditableValue, ListAttributeValue, ObjectItem, SelectionSingleValue } from "mendix";
import { ActionValue, EditableValue, ListAttributeValue, ObjectItem, SelectionSingleValue } from "mendix";
import {
ComboboxContainerProps,
LoadingTypeEnum,
Expand All @@ -11,6 +11,7 @@ import { DatabaseCaptionsProvider } from "./DatabaseCaptionsProvider";
import { DatabaseOptionsProvider } from "./DatabaseOptionsProvider";
import { DatabaseValuesProvider } from "./DatabaseValuesProvider";
import { extractDatabaseProps, getReadonly } from "./utils";
import { executeAction } from "@mendix/widget-plugin-platform/framework/execute-action";

export class DatabaseSingleSelectionSelector<T extends string | Big, R extends EditableValue<T>>
implements SingleSelector
Expand All @@ -30,6 +31,7 @@ export class DatabaseSingleSelectionSelector<T extends string | Big, R extends E

validation?: string = undefined;
values: DatabaseValuesProvider;
private onChangeEvent?: ActionValue;
protected _attr: R | undefined;
private selection?: SelectionSingleValue;

Expand All @@ -52,14 +54,16 @@ export class DatabaseSingleSelectionSelector<T extends string | Big, R extends E
filterType,
lazyLoading,
loadingType,
valueSourceAttribute
valueSourceAttribute,
onChangeEvent
} = extractDatabaseProps(props);

if (ds.status === "loading" && (!lazyLoading || ds.limit !== Infinity)) {
return;
}

this._attr = targetAttribute as R;
this.onChangeEvent = onChangeEvent;
this.readOnly = getReadonly(targetAttribute, props.customEditability, props.customEditabilityExpression);
this.lazyLoader.updateProps(ds);
this.lazyLoader.setLimit(
Expand Down Expand Up @@ -144,9 +148,19 @@ export class DatabaseSingleSelectionSelector<T extends string | Big, R extends E
}
}

setAttributeValue(value: T): void {
if (this._attr) {
const oldValue = this._attr.value;
this._attr.setValue(value);
if (!_valuesIsEqual(oldValue, value)) {
executeAction(this.onChangeEvent);
}
}
}

setValue(objectId: string | null): void {
const value = this.values.get(objectId) as T;
this._attr?.setValue(value);
this.setAttributeValue(value);
if (objectId !== (this.selection?.selection?.id ?? "")) {
this.selection?.setSelection(this.options._optionToValue(objectId));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
ActionValue,
DynamicValue,
EditableValue,
ListAttributeValue,
Expand Down Expand Up @@ -29,6 +30,7 @@ type ExtractionReturnValue = {
loadingType: LoadingTypeEnum;
valueSourceAttribute: ListAttributeValue<string | Big> | undefined;
filterInputDebounceInterval: number;
onChangeEvent: ActionValue | undefined;
};

export function extractDatabaseProps(props: ComboboxContainerProps): ExtractionReturnValue {
Expand Down Expand Up @@ -72,6 +74,8 @@ export function extractDatabaseProps(props: ComboboxContainerProps): ExtractionR
}
}

const onChangeEvent = props.onChangeEvent;

return {
targetAttribute,
captionProvider: captionType === "attribute" ? captionAttribute : captionExpression,
Expand All @@ -85,7 +89,8 @@ export function extractDatabaseProps(props: ComboboxContainerProps): ExtractionR
lazyLoading,
loadingType,
valueSourceAttribute,
filterInputDebounceInterval
filterInputDebounceInterval,
onChangeEvent
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ export interface ComboboxContainerProps {
optionsSourceDatabaseCaptionAttribute?: ListAttributeValue<string>;
optionsSourceAssociationCaptionExpression?: ListExpressionValue<string>;
optionsSourceDatabaseCaptionExpression?: ListExpressionValue<string>;
optionsSourceDatabaseValueAttribute?: ListAttributeValue<string | Big>;
databaseAttributeString?: EditableValue<string | Big>;
optionsSourceDatabaseValueAttribute?: ListAttributeValue<string | Big>;
attributeAssociation: ReferenceValue | ReferenceSetValue;
optionsSourceAssociationDataSource?: ListValue;
staticAttribute: EditableValue<string | Big | boolean | Date>;
Expand Down Expand Up @@ -120,8 +120,8 @@ export interface ComboboxPreviewProps {
optionsSourceDatabaseCaptionAttribute: string;
optionsSourceAssociationCaptionExpression: string;
optionsSourceDatabaseCaptionExpression: string;
optionsSourceDatabaseValueAttribute: string;
databaseAttributeString: string;
optionsSourceDatabaseValueAttribute: string;
attributeAssociation: string;
optionsSourceAssociationDataSource: {} | { caption: string } | { type: string } | null;
staticAttribute: string;
Expand Down
Loading