mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
AAE-24007 Display radio buttons and dropdown options depending on optionType (#9975)
* AAE-24007 Update form-field.moel * AAE-24007 Update dropdown-cloud.widget * AAE-24007 Update radio-buttons-cloud.widget * AAE-24007 Dropdown aligment (undefined value should be reserved for empty option) * AAE-24007 Minor update * AAE-24007 Update tests * AAE-24007 Update * AAE-24007 Update * AAE-24007 Update * AAE-24007 Fix units * AAE-24007 Fix * AAE-24007 Align standard dropdown and radio
This commit is contained in:
committed by
GitHub
parent
3406341859
commit
cb0b072b1e
@@ -82,7 +82,7 @@ describe('DropdownWidgetComponent', () => {
|
||||
beforeEach(() => {
|
||||
getRestFieldValuesSpy = spyOn(taskFormService, 'getRestFieldValues').and.returnValue(of([]));
|
||||
|
||||
widget.field = new FormFieldModel(new FormModel({ taskId }), { id: fieldId, restUrl: '<url>' });
|
||||
widget.field = new FormFieldModel(new FormModel({ taskId }), { id: fieldId, restUrl: '<url>', optionType: 'rest' });
|
||||
});
|
||||
|
||||
it('should request options from service when form is NOT readonly', () => {
|
||||
@@ -110,7 +110,7 @@ describe('DropdownWidgetComponent', () => {
|
||||
expect(element.querySelector('.adf-dropdown-required-message')).toBeNull();
|
||||
});
|
||||
|
||||
it('should preserve empty option when loading fields', () => {
|
||||
it('should NOT preserve empty option when loading fields', () => {
|
||||
const restFieldValue: FormFieldOption = { id: '1', name: 'Option1' } as FormFieldOption;
|
||||
spyOn(taskFormService, 'getRestFieldValues').and.callFake(
|
||||
() =>
|
||||
@@ -125,15 +125,15 @@ describe('DropdownWidgetComponent', () => {
|
||||
widget.field = new FormFieldModel(form, {
|
||||
id: '<id>',
|
||||
restUrl: '/some/url/address',
|
||||
optionType: 'rest',
|
||||
hasEmptyValue: true,
|
||||
options: [emptyOption]
|
||||
});
|
||||
widget.ngOnInit();
|
||||
|
||||
expect(taskFormService.getRestFieldValues).toHaveBeenCalled();
|
||||
expect(widget.field.options.length).toBe(2);
|
||||
expect(widget.field.options[0]).toBe(emptyOption);
|
||||
expect(widget.field.options[1]).toBe(restFieldValue);
|
||||
expect(widget.field.options.length).toBe(1);
|
||||
expect(widget.field.options[0]).toEqual(restFieldValue);
|
||||
});
|
||||
|
||||
describe('when is required', () => {
|
||||
@@ -187,7 +187,8 @@ describe('DropdownWidgetComponent', () => {
|
||||
name: 'date-name',
|
||||
type: 'dropdown',
|
||||
readOnly: 'false',
|
||||
restUrl: 'fake-rest-url'
|
||||
restUrl: 'fake-rest-url',
|
||||
optionType: 'rest'
|
||||
});
|
||||
widget.field.emptyOption = { id: 'empty', name: 'Choose one...' };
|
||||
widget.field.isVisible = true;
|
||||
@@ -237,7 +238,8 @@ describe('DropdownWidgetComponent', () => {
|
||||
name: 'date-name',
|
||||
type: 'dropdown',
|
||||
readOnly: 'false',
|
||||
restUrl: 'fake-rest-url'
|
||||
restUrl: 'fake-rest-url',
|
||||
optionType: 'rest'
|
||||
});
|
||||
widget.field.emptyOption = { id: 'empty', name: 'Choose one...' };
|
||||
widget.field.isVisible = true;
|
||||
|
@@ -52,7 +52,7 @@ export class DropdownWidgetComponent extends WidgetComponent implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
if (this.field?.restUrl && !this.isReadOnlyForm()) {
|
||||
if (this.isValidRestConfig() && !this.isReadOnlyForm()) {
|
||||
if (this.field.form.taskId) {
|
||||
this.getValuesByTaskId();
|
||||
} else {
|
||||
@@ -107,7 +107,19 @@ export class DropdownWidgetComponent extends WidgetComponent implements OnInit {
|
||||
return this.field.readOnly;
|
||||
}
|
||||
|
||||
private isRestType(): boolean {
|
||||
return this.field?.optionType === 'rest';
|
||||
}
|
||||
|
||||
private isReadOnlyForm(): boolean {
|
||||
return !!this.field?.form?.readOnly;
|
||||
}
|
||||
|
||||
private hasRestUrl(): boolean {
|
||||
return !!this.field?.restUrl;
|
||||
}
|
||||
|
||||
private isValidRestConfig(): boolean {
|
||||
return this.isRestType() && this.hasRestUrl();
|
||||
}
|
||||
}
|
||||
|
@@ -74,7 +74,7 @@ describe('RadioButtonsWidgetComponent', () => {
|
||||
|
||||
formService = new FormService();
|
||||
widget = new RadioButtonsWidgetComponent(formService, taskFormService, processDefinitionService);
|
||||
widget.field = new FormFieldModel(new FormModel(), { restUrl: '<url>' });
|
||||
widget.field = new FormFieldModel(new FormModel(), { restUrl: '<url>', optionType: 'rest' });
|
||||
});
|
||||
|
||||
it('should request field values from service', () => {
|
||||
@@ -87,7 +87,8 @@ describe('RadioButtonsWidgetComponent', () => {
|
||||
|
||||
widget.field = new FormFieldModel(form, {
|
||||
id: fieldId,
|
||||
restUrl: '<url>'
|
||||
restUrl: '<url>',
|
||||
optionType: 'rest'
|
||||
});
|
||||
|
||||
spyOn(taskFormService, 'getRestFieldValues').and.returnValue(
|
||||
@@ -110,7 +111,8 @@ describe('RadioButtonsWidgetComponent', () => {
|
||||
|
||||
widget.field = new FormFieldModel(form, {
|
||||
id: fieldId,
|
||||
restUrl: '<url>'
|
||||
restUrl: '<url>',
|
||||
optionType: 'rest'
|
||||
});
|
||||
const field = widget.field;
|
||||
spyOn(field, 'updateForm').and.stub();
|
||||
@@ -135,7 +137,8 @@ describe('RadioButtonsWidgetComponent', () => {
|
||||
|
||||
widget.field = new FormFieldModel(form, {
|
||||
id: fieldId,
|
||||
restUrl: '<url>'
|
||||
restUrl: '<url>',
|
||||
optionType: 'rest'
|
||||
});
|
||||
spyOn(taskFormService, 'getRestFieldValues').and.returnValue(
|
||||
new Observable((observer) => {
|
||||
@@ -364,7 +367,8 @@ describe('RadioButtonsWidgetComponent', () => {
|
||||
id: 'radio-id',
|
||||
name: 'radio-name',
|
||||
type: FormFieldTypes.RADIO_BUTTONS,
|
||||
restUrl: 'rest-url'
|
||||
restUrl: 'rest-url',
|
||||
optionType: 'rest'
|
||||
});
|
||||
radioButtonWidget.field.isVisible = true;
|
||||
const fakeContainer = new ContainerModel(radioButtonWidget.field);
|
||||
@@ -427,7 +431,8 @@ describe('RadioButtonsWidgetComponent', () => {
|
||||
id: 'radio-id',
|
||||
name: 'radio-name',
|
||||
type: FormFieldTypes.RADIO_BUTTONS,
|
||||
restUrl: 'rest-url'
|
||||
restUrl: 'rest-url',
|
||||
optionType: 'rest'
|
||||
});
|
||||
spyOn(processDefinitionService, 'getRestFieldValuesByProcessId').and.returnValue(of(restOption));
|
||||
radioButtonWidget.field.isVisible = true;
|
||||
|
@@ -55,7 +55,7 @@ export class RadioButtonsWidgetComponent extends WidgetComponent implements OnIn
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
if (this.field?.restUrl && !this.field?.form?.readOnly) {
|
||||
if (this.isValidRestConfig() && !this.isReadOnlyForm()) {
|
||||
if (this.field.form.taskId) {
|
||||
this.getOptionsByTaskId();
|
||||
} else {
|
||||
@@ -84,4 +84,20 @@ export class RadioButtonsWidgetComponent extends WidgetComponent implements OnIn
|
||||
this.field.value = optionSelected;
|
||||
this.fieldChanged.emit(this.field);
|
||||
}
|
||||
|
||||
private isRestType(): boolean {
|
||||
return this.field?.optionType === 'rest';
|
||||
}
|
||||
|
||||
private isReadOnlyForm(): boolean {
|
||||
return !!this.field?.form?.readOnly;
|
||||
}
|
||||
|
||||
private hasRestUrl(): boolean {
|
||||
return !!this.field?.restUrl;
|
||||
}
|
||||
|
||||
private isValidRestConfig(): boolean {
|
||||
return this.isRestType() && this.hasRestUrl();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user