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();
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -244,8 +244,8 @@ export class FormFieldModel extends FormWidgetModel {
|
||||
}
|
||||
|
||||
/*
|
||||
This is needed due to Activiti displaying/editing dates in d-M-YYYY format
|
||||
but storing on server in ISO8601 format (i.e. 2013-02-04T22:44:30.652Z)
|
||||
This is needed due to Activiti displaying/editing dates in d-M-YYYY format
|
||||
but storing on server in ISO8601 format (i.e. 2013-02-04T22:44:30.652Z)
|
||||
*/
|
||||
if (json.type === FormFieldTypes.DATE) {
|
||||
if (value) {
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -50,7 +50,7 @@ describe('DisplayValueWidget', () => {
|
||||
|
||||
it('should take field value on init', () => {
|
||||
let value = '<value>';
|
||||
widget.field = new FormFieldModel(null, {value: value});
|
||||
widget.field = new FormFieldModel(null, { value: value });
|
||||
widget.field.params = null;
|
||||
widget.ngOnInit();
|
||||
expect(widget.value).toBe(value);
|
||||
@@ -150,7 +150,7 @@ describe('DisplayValueWidget', () => {
|
||||
widget.field = new FormFieldModel(null, {
|
||||
type: FormFieldTypes.DISPLAY_VALUE,
|
||||
value: [
|
||||
{name: 'file1'}
|
||||
{ name: 'file1' }
|
||||
],
|
||||
params: {
|
||||
field: {
|
||||
@@ -238,8 +238,8 @@ describe('DisplayValueWidget', () => {
|
||||
restUrl: null,
|
||||
value: '2',
|
||||
options: [
|
||||
{id: '1', name: 'option 1'},
|
||||
{id: '2', name: 'option 2'}
|
||||
{ id: '1', name: 'option 1' },
|
||||
{ id: '2', name: 'option 2' }
|
||||
],
|
||||
params: {
|
||||
field: {
|
||||
@@ -257,8 +257,8 @@ describe('DisplayValueWidget', () => {
|
||||
restUrl: null,
|
||||
value: '100',
|
||||
options: [
|
||||
{id: '1', name: 'option 1'},
|
||||
{id: '2', name: 'option 2'}
|
||||
{ id: '1', name: 'option 1' },
|
||||
{ id: '2', name: 'option 2' }
|
||||
],
|
||||
params: {
|
||||
field: {
|
||||
@@ -306,22 +306,22 @@ describe('DisplayValueWidget', () => {
|
||||
spyOn(formService, 'getRestFieldValues').and.returnValue(
|
||||
Observable.create(observer => {
|
||||
observer.next([
|
||||
{id: '1', name: 'option 1'},
|
||||
{id: '2', name: 'option 2'}
|
||||
{ id: '1', name: 'option 1' },
|
||||
{ id: '2', name: 'option 2' }
|
||||
]);
|
||||
observer.complete();
|
||||
})
|
||||
);
|
||||
|
||||
let form = new FormModel({taskId: '<id>'});
|
||||
let form = new FormModel({ taskId: '<id>' });
|
||||
|
||||
widget.field = new FormFieldModel(form, {
|
||||
type: FormFieldTypes.DISPLAY_VALUE,
|
||||
restUrl: '<url>',
|
||||
value: '2',
|
||||
options: [
|
||||
{id: '1', name: 'option 1'},
|
||||
{id: '2', name: 'option 2'}
|
||||
{ id: '1', name: 'option 1' },
|
||||
{ id: '2', name: 'option 2' }
|
||||
],
|
||||
params: {
|
||||
field: {
|
||||
@@ -338,14 +338,14 @@ describe('DisplayValueWidget', () => {
|
||||
spyOn(formService, 'getRestFieldValues').and.returnValue(
|
||||
Observable.create(observer => {
|
||||
observer.next([
|
||||
{id: '1', name: 'option 1'},
|
||||
{id: '2', name: 'option 2'}
|
||||
{ id: '1', name: 'option 1' },
|
||||
{ id: '2', name: 'option 2' }
|
||||
]);
|
||||
observer.complete();
|
||||
})
|
||||
);
|
||||
|
||||
let form = new FormModel({taskId: '<id>'});
|
||||
let form = new FormModel({ taskId: '<id>' });
|
||||
|
||||
widget.field = new FormFieldModel(form, {
|
||||
type: FormFieldTypes.DISPLAY_VALUE,
|
||||
@@ -370,7 +370,7 @@ describe('DisplayValueWidget', () => {
|
||||
})
|
||||
);
|
||||
|
||||
let form = new FormModel({taskId: '<id>'});
|
||||
let form = new FormModel({ taskId: '<id>' });
|
||||
|
||||
widget.field = new FormFieldModel(form, {
|
||||
type: FormFieldTypes.DISPLAY_VALUE,
|
||||
@@ -393,7 +393,7 @@ describe('DisplayValueWidget', () => {
|
||||
Observable.throw(error)
|
||||
);
|
||||
|
||||
let form = new FormModel({taskId: '<id>'});
|
||||
let form = new FormModel({ taskId: '<id>' });
|
||||
|
||||
widget.field = new FormFieldModel(form, {
|
||||
type: FormFieldTypes.DISPLAY_VALUE,
|
||||
@@ -628,7 +628,7 @@ describe('DisplayValueWidget', () => {
|
||||
FormService,
|
||||
WidgetVisibilityService
|
||||
],
|
||||
schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
|
||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||
}).compileComponents().then(() => {
|
||||
fixture = TestBed.createComponent(DisplayValueWidget);
|
||||
widgetUI = fixture.componentInstance;
|
||||
@@ -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