Activiti form - Dropdown display label in complete form (#1777)

* Dropdown - retrieve the label instead of the id

* Add unit test

* Use find instead of filter
This commit is contained in:
Maurizio Vitale 2017-03-30 18:14:22 +01:00 committed by Denys Vuika
parent 406d96d5bf
commit 952df8d81c
3 changed files with 19 additions and 1 deletions

View File

@ -121,6 +121,19 @@ describe('FormFieldModel', () => {
expect(field.value).toBe('deferred'); expect(field.value).toBe('deferred');
}); });
it('should return the label of selected dropdown value ', () => {
let field = new FormFieldModel(new FormModel(), {
type: FormFieldTypes.DROPDOWN,
options: [
{id: 'fake-option-1', name: 'fake label 1'},
{id: 'fake-option-2', name: 'fake label 2'},
{id: 'fake-option-3', name: 'fake label 3'}
],
value: 'fake-option-2'
});
expect(field.getOptionName()).toBe('fake label 2');
});
it('should parse and resolve radio button value', () => { it('should parse and resolve radio button value', () => {
let field = new FormFieldModel(new FormModel(), { let field = new FormFieldModel(new FormModel(), {
type: FormFieldTypes.RADIO_BUTTONS, type: FormFieldTypes.RADIO_BUTTONS,

View File

@ -340,4 +340,9 @@ export class FormFieldModel extends FormWidgetModel {
return false; return false;
} }
} }
getOptionName(): string {
let option: FormFieldOption = this.options.find(opt => opt.id === this.value);
return option ? option.name : null;
}
} }

View File

@ -103,7 +103,7 @@ export class DisplayValueWidget extends WidgetComponent implements OnInit {
if (this.field.restUrl) { if (this.field.restUrl) {
this.loadRestFieldValue(); this.loadRestFieldValue();
} else { } else {
this.value = this.field.value; this.value = this.field.getOptionName();
} }
break; break;
case FormFieldTypes.RADIO_BUTTONS: case FormFieldTypes.RADIO_BUTTONS: