mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
dropdown form field return object
This commit is contained in:
+15
-1
@@ -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',
|
||||
|
||||
+5
-1
@@ -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;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user