dropdown form field return object

This commit is contained in:
eromano
2025-05-15 11:37:53 +02:00
parent cf9d296d0f
commit e3a1cd1202
5 changed files with 42 additions and 8 deletions
@@ -983,7 +983,7 @@ describe('DropdownCloudWidgetComponent', () => {
expect(widget.field.options.length).toEqual(0);
};
it('should set dropdownControl value without emitting events', () => {
it('should set dropdownControl value without emitting events if the mapping is a string', () => {
widget.field = {
value: 'testValue',
options: [],
@@ -997,6 +997,20 @@ describe('DropdownCloudWidgetComponent', () => {
expect(widget.dropdownControl.value).toEqual({ id: 'testValue', name: '' });
});
it('should set dropdownControl value without emitting events if is an object', () => {
widget.field = {
value: { id: 'testValueObj', name: 'testValueObjName' },
options: [],
isVisible: true
} as any; // Mock field
spyOn(widget.dropdownControl, 'setValue').and.callThrough();
widget['setFormControlValue']();
expect(widget.dropdownControl.setValue).toHaveBeenCalledWith({ id: 'testValueObj', name: 'testValueObjName' }, { emitEvent: false });
expect(widget.dropdownControl.value).toEqual({ id: 'testValue', name: '' });
});
it('should display options persisted from process variable', async () => {
widget.field = getVariableDropdownWidget(
'variables.json-variable',
@@ -195,7 +195,11 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI
}
private setFormControlValue(): void {
this.dropdownControl.setValue({ id: this.field?.value, name: '' }, { emitEvent: false });
if (this.field?.value && typeof this.field?.value === 'object') {
this.dropdownControl.setValue(this.field?.value, { emitEvent: false });
} else {
this.dropdownControl.setValue({ id: this.field?.value, name: '' }, { emitEvent: false });
}
}
private updateFormControlState(): void {
@@ -29,7 +29,8 @@ export const defaultValueValidator =
});
const isSomeOptionSelected = optionsWithNoDefaultValue.some((dropdownOption) => {
const isOptionSelected = dropdownOption.id === control.value?.id;
const isOptionSelected = dropdownOption.id === control.value.id;
return isOptionSelected;
});