mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AAE-6093] - fixed rest option for cloud widget (#7304)
* [AAE-6093] - fixed rest option for cloud widget * [AAE-6093] - reverted app config change * [AAE-6093] - fixed naming * [AAE-6093] - fixed radio button complete task and added support for rest url with the new feature * [AAE-6093] - removed test value * [AAE-6093] - fixed lint * [AAE-6093] - fixed lint * [AAE-6093] - merged fix for dropdown
This commit is contained in:
@@ -691,6 +691,98 @@ describe('FormFieldModel', () => {
|
||||
expect(form.values['dropdown_field'].name).toEqual('Option 1');
|
||||
});
|
||||
|
||||
it('dropdown field type should be formatted on rest properties', () => {
|
||||
const form = new FormModel();
|
||||
const field = new FormFieldModel(form, {
|
||||
fieldType: 'HeaderFieldtype',
|
||||
id: 'dropdown_field',
|
||||
name: 'header',
|
||||
type: FormFieldTypes.DROPDOWN,
|
||||
value: 'opt1',
|
||||
required: false,
|
||||
readOnly: true,
|
||||
restUrl: 'fake-url-just-to-show',
|
||||
optionType: 'rest',
|
||||
restIdProperty: 'fake-id-property',
|
||||
restLabelProperty: 'fake-label-property',
|
||||
options: [
|
||||
{id: 'opt1', name: 'Option 1'},
|
||||
{id: 'opt2', name: 'Option 2'}
|
||||
]
|
||||
});
|
||||
field.updateForm();
|
||||
expect(form.values['dropdown_field']['fake-id-property']).toEqual('opt1');
|
||||
expect(form.values['dropdown_field']['fake-label-property']).toEqual('Option 1');
|
||||
});
|
||||
|
||||
it('dropdown field type should be formatted on id and name properties if rest properties are not set', () => {
|
||||
const form = new FormModel();
|
||||
const field = new FormFieldModel(form, {
|
||||
fieldType: 'HeaderFieldtype',
|
||||
id: 'dropdown_field',
|
||||
name: 'header',
|
||||
type: FormFieldTypes.DROPDOWN,
|
||||
value: 'opt1',
|
||||
required: false,
|
||||
readOnly: true,
|
||||
restUrl: 'fake-url-just-to-show',
|
||||
optionType: 'rest',
|
||||
options: [
|
||||
{id: 'opt1', name: 'Option 1'},
|
||||
{id: 'opt2', name: 'Option 2'}
|
||||
]
|
||||
});
|
||||
field.updateForm();
|
||||
expect(form.values['dropdown_field']['id']).toEqual('opt1');
|
||||
expect(form.values['dropdown_field']['name']).toEqual('Option 1');
|
||||
});
|
||||
|
||||
it('radio button field rest type should appear with its configured label and id into the rest values', () => {
|
||||
const form = new FormModel();
|
||||
const field = new FormFieldModel(form, {
|
||||
fieldType: 'HeaderFieldtype',
|
||||
id: 'radio_bananan_field',
|
||||
name: 'banana',
|
||||
type: FormFieldTypes.RADIO_BUTTONS,
|
||||
value: 'opt1',
|
||||
required: false,
|
||||
readOnly: true,
|
||||
restUrl: '<whatever-url-you-like-we-do-not-mind>',
|
||||
restIdProperty: 'banana',
|
||||
restLabelProperty: 'banLabel',
|
||||
optionType: 'rest',
|
||||
options: [
|
||||
{id: 'opt1', name: 'Option 1'},
|
||||
{id: 'opt2', name: 'Option 2'}
|
||||
]
|
||||
});
|
||||
field.updateForm();
|
||||
expect(form.values['radio_bananan_field']['banana']).toEqual('opt1');
|
||||
expect(form.values['radio_bananan_field']['banLabel']).toEqual('Option 1');
|
||||
});
|
||||
|
||||
it('radio button field rest type should appear with id / name properties when rest properties are not configured', () => {
|
||||
const form = new FormModel();
|
||||
const field = new FormFieldModel(form, {
|
||||
fieldType: 'HeaderFieldtype',
|
||||
id: 'radio_bananan_field',
|
||||
name: 'banana',
|
||||
type: FormFieldTypes.RADIO_BUTTONS,
|
||||
value: 'opt1',
|
||||
required: false,
|
||||
readOnly: true,
|
||||
restUrl: '<whatever-url-you-like-we-do-not-mind>',
|
||||
optionType: 'rest',
|
||||
options: [
|
||||
{id: 'opt1', name: 'Option 1'},
|
||||
{id: 'opt2', name: 'Option 2'}
|
||||
]
|
||||
});
|
||||
field.updateForm();
|
||||
expect(form.values['radio_bananan_field']['id']).toEqual('opt1');
|
||||
expect(form.values['radio_bananan_field']['name']).toEqual('Option 1');
|
||||
});
|
||||
|
||||
it('should parse and resolve people null value as null', () => {
|
||||
const field = new FormFieldModel(new FormModel(), {
|
||||
type: FormFieldTypes.PEOPLE,
|
||||
|
@@ -62,7 +62,7 @@ export class FormFieldModel extends FormWidgetModel {
|
||||
restLabelProperty: string;
|
||||
hasEmptyValue: boolean;
|
||||
className: string;
|
||||
optionType: string;
|
||||
optionType: 'rest' | 'manual' ;
|
||||
params: FormFieldMetadata = {};
|
||||
hyperlinkUrl: string;
|
||||
displayText: string;
|
||||
@@ -372,18 +372,14 @@ export class FormFieldModel extends FormWidgetModel {
|
||||
|
||||
const entry: FormFieldOption[] = this.options.filter((opt) => opt.id === this.value);
|
||||
if (entry.length > 0) {
|
||||
this.form.values[this.id] = entry[0];
|
||||
this.setFormFieldValueOption(entry[0]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FormFieldTypes.RADIO_BUTTONS:
|
||||
/*
|
||||
This is needed due to Activiti issue related to reading radio button values as value string
|
||||
but saving back as object: { id: <id>, name: <name> }
|
||||
*/
|
||||
const radioButton: FormFieldOption[] = this.options.filter((opt) => opt.id === this.value);
|
||||
if (radioButton.length > 0) {
|
||||
this.form.values[this.id] = radioButton[0];
|
||||
this.setFormFieldValueOption(radioButton[0]);
|
||||
}
|
||||
break;
|
||||
case FormFieldTypes.UPLOAD:
|
||||
@@ -491,4 +487,17 @@ export class FormFieldModel extends FormWidgetModel {
|
||||
json.type === FormFieldTypes.BOOLEAN;
|
||||
}
|
||||
|
||||
private setFormFieldValueOption(option: FormFieldOption ) {
|
||||
if (this.optionType === 'rest' && !!this.restUrl) {
|
||||
const restEntry = {};
|
||||
const restIdProperty = this.restIdProperty || 'id';
|
||||
const restLabelProperty = this.restLabelProperty || 'name';
|
||||
restEntry[restIdProperty] = option.id;
|
||||
restEntry[restLabelProperty] = option.name;
|
||||
this.form.values[this.id] = restEntry;
|
||||
} else {
|
||||
this.form.values[this.id] = option;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user