1- import { EditableValue , ListAttributeValue , ObjectItem , SelectionSingleValue } from "mendix" ;
1+ import { ActionValue , EditableValue , ListAttributeValue , ObjectItem , SelectionSingleValue } from "mendix" ;
22import {
33 ComboboxContainerProps ,
44 LoadingTypeEnum ,
@@ -11,6 +11,7 @@ import { DatabaseCaptionsProvider } from "./DatabaseCaptionsProvider";
1111import { DatabaseOptionsProvider } from "./DatabaseOptionsProvider" ;
1212import { DatabaseValuesProvider } from "./DatabaseValuesProvider" ;
1313import { extractDatabaseProps , getReadonly } from "./utils" ;
14+ import { executeAction } from "@mendix/widget-plugin-platform/framework/execute-action" ;
1415
1516export class DatabaseSingleSelectionSelector < T extends string | Big , R extends EditableValue < T > >
1617 implements SingleSelector
@@ -30,6 +31,7 @@ export class DatabaseSingleSelectionSelector<T extends string | Big, R extends E
3031
3132 validation ?: string = undefined ;
3233 values : DatabaseValuesProvider ;
34+ private onChangeEvent ?: ActionValue ;
3335 protected _attr : R | undefined ;
3436 private selection ?: SelectionSingleValue ;
3537
@@ -52,14 +54,16 @@ export class DatabaseSingleSelectionSelector<T extends string | Big, R extends E
5254 filterType,
5355 lazyLoading,
5456 loadingType,
55- valueSourceAttribute
57+ valueSourceAttribute,
58+ onChangeEvent
5659 } = extractDatabaseProps ( props ) ;
5760
5861 if ( ds . status === "loading" && ( ! lazyLoading || ds . limit !== Infinity ) ) {
5962 return ;
6063 }
6164
6265 this . _attr = targetAttribute as R ;
66+ this . onChangeEvent = onChangeEvent ;
6367 this . readOnly = getReadonly ( targetAttribute , props . customEditability , props . customEditabilityExpression ) ;
6468 this . lazyLoader . updateProps ( ds ) ;
6569 this . lazyLoader . setLimit (
@@ -144,9 +148,19 @@ export class DatabaseSingleSelectionSelector<T extends string | Big, R extends E
144148 }
145149 }
146150
151+ setAttributeValue ( value : T ) : void {
152+ if ( this . _attr ) {
153+ const oldValue = this . _attr . value ;
154+ this . _attr . setValue ( value ) ;
155+ if ( ! _valuesIsEqual ( oldValue , value ) ) {
156+ executeAction ( this . onChangeEvent ) ;
157+ }
158+ }
159+ }
160+
147161 setValue ( objectId : string | null ) : void {
148162 const value = this . values . get ( objectId ) as T ;
149- this . _attr ?. setValue ( value ) ;
163+ this . setAttributeValue ( value ) ;
150164 if ( objectId !== ( this . selection ?. selection ?. id ?? "" ) ) {
151165 this . selection ?. setSelection ( this . options . _optionToValue ( objectId ) ) ;
152166 }
0 commit comments