mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2199] fixed check for radio button and dropdown (#2910)
This commit is contained in:
@@ -438,10 +438,10 @@ describe('WidgetVisibilityService', () => {
|
|||||||
expect(leftValue).toBe('value_2');
|
expect(leftValue).toBe('value_2');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return undefined for a value that is not on variable or form', () => {
|
it('should return an empty string for a value that is not on variable or form', () => {
|
||||||
let leftValue = service.getLeftValue(fakeFormWithField, visibilityObjTest);
|
let leftValue = service.getLeftValue(fakeFormWithField, visibilityObjTest);
|
||||||
|
|
||||||
expect(leftValue).toBeUndefined();
|
expect(leftValue).toBe('');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should evaluate the visibility for the field with single visibility condition between two field values', () => {
|
it('should evaluate the visibility for the field with single visibility condition between two field values', () => {
|
||||||
@@ -612,25 +612,23 @@ describe('WidgetVisibilityService', () => {
|
|||||||
expect(res).toBe('value_1');
|
expect(res).toBe('value_1');
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
it('should refresh the visibility for field', () => {
|
||||||
it('should refresh the visibility for field', () => {
|
visibilityObjTest.leftFormFieldId = 'FIELD_TEST';
|
||||||
visibilityObjTest.leftFormFieldId = 'FIELD_TEST';
|
visibilityObjTest.operator = '!=';
|
||||||
visibilityObjTest.operator = '!=';
|
visibilityObjTest.rightFormFieldId = 'RIGHT_FORM_FIELD_ID';
|
||||||
visibilityObjTest.rightFormFieldId = 'RIGHT_FORM_FIELD_ID';
|
|
||||||
|
|
||||||
let container = <ContainerModel> fakeFormWithField.fields[0];
|
let container = <ContainerModel> fakeFormWithField.fields[0];
|
||||||
let column0 = container.columns[0];
|
let column0 = container.field.columns[0];
|
||||||
let column1 = container.columns[1];
|
let column1 = container.field.columns[1];
|
||||||
|
|
||||||
column0.fields[0].visibilityCondition = visibilityObjTest;
|
column0.fields[0].visibilityCondition = visibilityObjTest;
|
||||||
service.refreshVisibility(fakeFormWithField);
|
service.refreshVisibility(fakeFormWithField);
|
||||||
|
|
||||||
expect(column0.fields[0].isVisible).toBeFalsy();
|
expect(column0.fields[0].isVisible).toBeFalsy();
|
||||||
expect(column0.fields[1].isVisible).toBeTruthy();
|
expect(column0.fields[1].isVisible).toBeTruthy();
|
||||||
expect(column0.fields[2].isVisible).toBeTruthy();
|
expect(column0.fields[2].isVisible).toBeTruthy();
|
||||||
expect(column1.fields[0].isVisible).toBeTruthy();
|
expect(column1.fields[0].isVisible).toBeTruthy();
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
|
|
||||||
it('should refresh the visibility for tab in forms', () => {
|
it('should refresh the visibility for tab in forms', () => {
|
||||||
visibilityObjTest.leftFormFieldId = 'FIELD_TEST';
|
visibilityObjTest.leftFormFieldId = 'FIELD_TEST';
|
||||||
@@ -655,9 +653,9 @@ describe('WidgetVisibilityService', () => {
|
|||||||
expect(tab.isVisible).toBeFalsy();
|
expect(tab.isVisible).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
xit('should refresh the visibility for container in forms', () => {
|
it('should refresh the visibility for container in forms', () => {
|
||||||
visibilityObjTest.leftFormFieldId = 'FIELD_TEST';
|
visibilityObjTest.leftFormFieldId = 'FIELD_TEST';
|
||||||
visibilityObjTest.operator = '!=';
|
visibilityObjTest.operator = '==';
|
||||||
visibilityObjTest.rightFormFieldId = 'LEFT_FORM_FIELD_ID';
|
visibilityObjTest.rightFormFieldId = 'LEFT_FORM_FIELD_ID';
|
||||||
let contModel = new ContainerModel(new FormFieldModel(fakeFormWithField, {
|
let contModel = new ContainerModel(new FormFieldModel(fakeFormWithField, {
|
||||||
id: 'fake-container-id',
|
id: 'fake-container-id',
|
||||||
|
@@ -78,8 +78,8 @@ export class WidgetVisibilityService {
|
|||||||
if (visibilityObj.leftRestResponseId && visibilityObj.leftRestResponseId !== 'null') {
|
if (visibilityObj.leftRestResponseId && visibilityObj.leftRestResponseId !== 'null') {
|
||||||
leftValue = this.getVariableValue(form, visibilityObj.leftRestResponseId, this.processVarList);
|
leftValue = this.getVariableValue(form, visibilityObj.leftRestResponseId, this.processVarList);
|
||||||
} else {
|
} else {
|
||||||
leftValue = this.getFormValue(form, visibilityObj.leftFormFieldId);
|
leftValue = this.getVariableValue(form, visibilityObj.leftFormFieldId, this.processVarList);
|
||||||
leftValue = leftValue ? leftValue : this.getVariableValue(form, visibilityObj.leftFormFieldId, this.processVarList);
|
leftValue = leftValue ? leftValue : this.getFormValue(form, visibilityObj.leftFormFieldId);
|
||||||
}
|
}
|
||||||
return leftValue;
|
return leftValue;
|
||||||
}
|
}
|
||||||
@@ -129,7 +129,7 @@ export class WidgetVisibilityService {
|
|||||||
let fieldValue = '';
|
let fieldValue = '';
|
||||||
form.getFormFields().forEach((formField: FormFieldModel) => {
|
form.getFormFields().forEach((formField: FormFieldModel) => {
|
||||||
if (this.isSearchedField(formField, fieldId)) {
|
if (this.isSearchedField(formField, fieldId)) {
|
||||||
fieldValue = this.getObjectValue(formField);
|
fieldValue = this.getObjectValue(formField, fieldId);
|
||||||
if (!fieldValue) {
|
if (!fieldValue) {
|
||||||
if (formField.value && formField.value.id) {
|
if (formField.value && formField.value.id) {
|
||||||
fieldValue = formField.value.id;
|
fieldValue = formField.value.id;
|
||||||
@@ -143,22 +143,29 @@ export class WidgetVisibilityService {
|
|||||||
return fieldValue;
|
return fieldValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private getObjectValue(field: FormFieldModel) {
|
private getObjectValue(field: FormFieldModel, fieldId: string) {
|
||||||
let value = '';
|
let value = '';
|
||||||
if (field.value && field.value.name) {
|
if (field.value && field.value.name) {
|
||||||
value = field.value.name;
|
value = field.value.name;
|
||||||
} else if (field.options) {
|
} else if (field.options) {
|
||||||
let option = field.options.find(opt => opt.id === field.value);
|
let option = field.options.find(opt => opt.id === field.value);
|
||||||
if (option) {
|
if (option) {
|
||||||
value = option.name;
|
value = this.getValueFromOption(fieldId, option);
|
||||||
} else {
|
|
||||||
|
|
||||||
value = field.value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getValueFromOption(fieldId: string, option): string {
|
||||||
|
let optionValue = '';
|
||||||
|
if (fieldId && fieldId.indexOf('_LABEL') > 0) {
|
||||||
|
optionValue = option.name;
|
||||||
|
} else {
|
||||||
|
optionValue = option.id;
|
||||||
|
}
|
||||||
|
return optionValue;
|
||||||
|
}
|
||||||
|
|
||||||
private isSearchedField(field: FormFieldModel, fieldToFind: string): boolean {
|
private isSearchedField(field: FormFieldModel, fieldToFind: string): boolean {
|
||||||
let formattedFieldName = this.removeLabel(field, fieldToFind);
|
let formattedFieldName = this.removeLabel(field, fieldToFind);
|
||||||
return field.id ? field.id.toUpperCase() === formattedFieldName.toUpperCase() : false;
|
return field.id ? field.id.toUpperCase() === formattedFieldName.toUpperCase() : false;
|
||||||
|
Reference in New Issue
Block a user