mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-647] Fix retrieving value for dropdown (#1888)
* [ADF-647] Fix retrieving value for dropdown
This commit is contained in:
@@ -332,4 +332,28 @@ describe('FormFieldModel', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to check if the field has options available', () =>{
|
||||
let form = new FormModel();
|
||||
let field = new FormFieldModel(form, {
|
||||
id: 'dropdown-happy',
|
||||
type: FormFieldTypes.DROPDOWN,
|
||||
options: [
|
||||
{ id: 'opt1', name: 'Option 1' },
|
||||
{ id: 'opt2', name: 'Option 2' }
|
||||
]
|
||||
});
|
||||
|
||||
expect(field.hasOptions()).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should return false if field has no options', () =>{
|
||||
let form = new FormModel();
|
||||
let field = new FormFieldModel(form, {
|
||||
id: 'dropdown-sad',
|
||||
type: FormFieldTypes.DROPDOWN
|
||||
});
|
||||
|
||||
expect(field.hasOptions()).toBeFalsy();
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -355,4 +355,8 @@ export class FormFieldModel extends FormWidgetModel {
|
||||
let option: FormFieldOption = this.options.find(opt => opt.id === this.value);
|
||||
return option ? option.name : null;
|
||||
}
|
||||
|
||||
hasOptions() {
|
||||
return this.options && this.options.length > 0;
|
||||
}
|
||||
}
|
||||
|
@@ -686,5 +686,51 @@ describe('DisplayValueWidget', () => {
|
||||
expect(elWidget.checked).toBeFalsy();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should show the dropdown value taken from options when field has options', async(() => {
|
||||
widgetUI.field = new FormFieldModel(null, {
|
||||
id: 'fake-dropdown-id',
|
||||
type: FormFieldTypes.DISPLAY_VALUE,
|
||||
value: '1',
|
||||
options: [
|
||||
{ id: '1', name: 'Option 1' },
|
||||
{ id: '2', name: 'Option 2' }
|
||||
],
|
||||
params: {
|
||||
field: {
|
||||
type: FormFieldTypes.DROPDOWN
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
fixture.whenStable()
|
||||
.then(() => {
|
||||
fixture.detectChanges();
|
||||
let elWidget: any = element.querySelector('#fake-dropdown-id');
|
||||
expect(elWidget).toBeDefined();
|
||||
expect(elWidget.value).toBe('Option 1');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should show the dropdown value taken from value when field has no options', async(() => {
|
||||
widgetUI.field = new FormFieldModel(null, {
|
||||
id: 'fake-dropdown-id',
|
||||
type: FormFieldTypes.DISPLAY_VALUE,
|
||||
value: 'FAKE',
|
||||
params: {
|
||||
field: {
|
||||
type: FormFieldTypes.DROPDOWN
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
fixture.whenStable()
|
||||
.then(() => {
|
||||
fixture.detectChanges();
|
||||
let elWidget: any = element.querySelector('#fake-dropdown-id');
|
||||
expect(elWidget).toBeDefined();
|
||||
expect(elWidget.value).toBe('FAKE');
|
||||
});
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
@@ -99,7 +99,6 @@ export class DisplayValueWidget extends WidgetComponent implements OnInit {
|
||||
}
|
||||
break;
|
||||
case FormFieldTypes.DOCUMENT:
|
||||
console.log('document');
|
||||
const file = this.field.value;
|
||||
if (file) {
|
||||
this.value = decodeURI(file.name);
|
||||
@@ -117,7 +116,7 @@ export class DisplayValueWidget extends WidgetComponent implements OnInit {
|
||||
if (this.field.restUrl) {
|
||||
this.loadRestFieldValue();
|
||||
} else {
|
||||
this.value = this.field.getOptionName();
|
||||
this.value = this.field.hasOptions() ? this.field.getOptionName() : this.value;
|
||||
}
|
||||
break;
|
||||
case FormFieldTypes.RADIO_BUTTONS:
|
||||
|
Reference in New Issue
Block a user