dropdown form field return object

This commit is contained in:
eromano
2025-05-15 12:57:01 +02:00
parent e3a1cd1202
commit 8a17d7fcf6
4 changed files with 28 additions and 4 deletions
@@ -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);
}
}
}
@@ -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;
});