mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-09-17 14:21:29 +00:00
dropdown form field return object
This commit is contained in:
@@ -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', () => {
|
||||
|
@@ -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: {
|
||||
|
@@ -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;
|
||||
});
|
||||
|
Reference in New Issue
Block a user