diff --git a/lib/core/src/lib/form/components/widgets/core/form-field.model.spec.ts b/lib/core/src/lib/form/components/widgets/core/form-field.model.spec.ts index 8fe1816c96..446f7d43eb 100644 --- a/lib/core/src/lib/form/components/widgets/core/form-field.model.spec.ts +++ b/lib/core/src/lib/form/components/widgets/core/form-field.model.spec.ts @@ -785,7 +785,7 @@ describe('FormFieldModel', () => { ]; }); - it('should update form with selected option and options from which we chose', () => { + it('should update form with selected option and options from which we chose when is a strign', () => { field.value = 'restOpt2'; field.updateForm(); @@ -1046,6 +1046,15 @@ describe('FormFieldModel', () => { expect(field.value).toEqual('opt2'); expect(field.form.values['dropdown_field']).toEqual({ id: 'opt2', name: 'Option 2' }); }); + + it('should selected option appear in form values', () => { + const field = getFieldConfig('manual', staticOptions, { id: 'opt3', name: 'opt3' }); + + field.updateForm(); + + expect(field.value).toEqual('opt2'); + expect(field.form.values['dropdown_field']).toEqual({ id: 'opt2', name: 'Option 2' }); + }); }); describe('radio buttons field', () => { diff --git a/lib/core/src/lib/form/components/widgets/core/form-field.model.ts b/lib/core/src/lib/form/components/widgets/core/form-field.model.ts index 3c60ebdb91..aa4b2a5ad4 100644 --- a/lib/core/src/lib/form/components/widgets/core/form-field.model.ts +++ b/lib/core/src/lib/form/components/widgets/core/form-field.model.ts @@ -436,6 +436,17 @@ export class FormFieldModel extends FormWidgetModel { this.form.values[this.id] = matchingOption || null; } + + if (typeof this.value === 'object') { + if (this.value.id === 'empty' || this.value.id === '') { + this.form.values[this.id] = null; + break; + } + + const matchingOption: FormFieldOption = this.options.find((opt) => opt.id === this.value.id); + + this.form.values[this.id] = matchingOption || null; + } break; } case FormFieldTypes.RADIO_BUTTONS: { diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.ts b/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.ts index 0b714193fa..a722d7827b 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/dropdown-cloud.widget.ts @@ -196,7 +196,7 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI private setFormControlValue(): void { if (this.field?.value && typeof this.field?.value === 'object') { - this.dropdownControl.setValue(this.field?.value, { emitEvent: false }); + this.dropdownControl.setValue({ id: this.field?.value.id, name: this.field?.value.name }, { emitEvent: false }); } else { this.dropdownControl.setValue({ id: this.field?.value, name: '' }, { emitEvent: false }); } @@ -473,7 +473,11 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI const fieldValueIds = this.field.value.map((valueOption) => valueOption.id); return fieldValueIds.every((valueOptionId) => optionIdList.includes(valueOptionId)); } else { - return [...this.field.options].map((option) => option.id).includes(this.field.value); + if (this.field?.value && typeof this.field?.value === 'object') { + return [...this.field.options].map((option) => option.id).includes(this.field.value.id); + } else { + return [...this.field.options].map((option) => option.id).includes(this.field.value); + } } } diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/validators.ts b/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/validators.ts index ed8b1fe52c..6b0c6fb872 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/validators.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/dropdown/validators.ts @@ -29,7 +29,7 @@ export const defaultValueValidator = }); const isSomeOptionSelected = optionsWithNoDefaultValue.some((dropdownOption) => { - const isOptionSelected = dropdownOption.id === control.value.id; + const isOptionSelected = dropdownOption.id === control.value?.id; return isOptionSelected; });