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');
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
expect(leftValue).toBeUndefined();
|
||||
expect(leftValue).toBe('');
|
||||
});
|
||||
|
||||
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');
|
||||
});
|
||||
|
||||
/*
|
||||
it('should refresh the visibility for field', () => {
|
||||
visibilityObjTest.leftFormFieldId = 'FIELD_TEST';
|
||||
visibilityObjTest.operator = '!=';
|
||||
visibilityObjTest.rightFormFieldId = 'RIGHT_FORM_FIELD_ID';
|
||||
it('should refresh the visibility for field', () => {
|
||||
visibilityObjTest.leftFormFieldId = 'FIELD_TEST';
|
||||
visibilityObjTest.operator = '!=';
|
||||
visibilityObjTest.rightFormFieldId = 'RIGHT_FORM_FIELD_ID';
|
||||
|
||||
let container = <ContainerModel> fakeFormWithField.fields[0];
|
||||
let column0 = container.columns[0];
|
||||
let column1 = container.columns[1];
|
||||
let container = <ContainerModel> fakeFormWithField.fields[0];
|
||||
let column0 = container.field.columns[0];
|
||||
let column1 = container.field.columns[1];
|
||||
|
||||
column0.fields[0].visibilityCondition = visibilityObjTest;
|
||||
service.refreshVisibility(fakeFormWithField);
|
||||
column0.fields[0].visibilityCondition = visibilityObjTest;
|
||||
service.refreshVisibility(fakeFormWithField);
|
||||
|
||||
expect(column0.fields[0].isVisible).toBeFalsy();
|
||||
expect(column0.fields[1].isVisible).toBeTruthy();
|
||||
expect(column0.fields[2].isVisible).toBeTruthy();
|
||||
expect(column1.fields[0].isVisible).toBeTruthy();
|
||||
});
|
||||
*/
|
||||
expect(column0.fields[0].isVisible).toBeFalsy();
|
||||
expect(column0.fields[1].isVisible).toBeTruthy();
|
||||
expect(column0.fields[2].isVisible).toBeTruthy();
|
||||
expect(column1.fields[0].isVisible).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should refresh the visibility for tab in forms', () => {
|
||||
visibilityObjTest.leftFormFieldId = 'FIELD_TEST';
|
||||
@@ -655,9 +653,9 @@ describe('WidgetVisibilityService', () => {
|
||||
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.operator = '!=';
|
||||
visibilityObjTest.operator = '==';
|
||||
visibilityObjTest.rightFormFieldId = 'LEFT_FORM_FIELD_ID';
|
||||
let contModel = new ContainerModel(new FormFieldModel(fakeFormWithField, {
|
||||
id: 'fake-container-id',
|
||||
|
@@ -78,8 +78,8 @@ export class WidgetVisibilityService {
|
||||
if (visibilityObj.leftRestResponseId && visibilityObj.leftRestResponseId !== 'null') {
|
||||
leftValue = this.getVariableValue(form, visibilityObj.leftRestResponseId, this.processVarList);
|
||||
} else {
|
||||
leftValue = this.getFormValue(form, visibilityObj.leftFormFieldId);
|
||||
leftValue = leftValue ? leftValue : this.getVariableValue(form, visibilityObj.leftFormFieldId, this.processVarList);
|
||||
leftValue = this.getVariableValue(form, visibilityObj.leftFormFieldId, this.processVarList);
|
||||
leftValue = leftValue ? leftValue : this.getFormValue(form, visibilityObj.leftFormFieldId);
|
||||
}
|
||||
return leftValue;
|
||||
}
|
||||
@@ -129,7 +129,7 @@ export class WidgetVisibilityService {
|
||||
let fieldValue = '';
|
||||
form.getFormFields().forEach((formField: FormFieldModel) => {
|
||||
if (this.isSearchedField(formField, fieldId)) {
|
||||
fieldValue = this.getObjectValue(formField);
|
||||
fieldValue = this.getObjectValue(formField, fieldId);
|
||||
if (!fieldValue) {
|
||||
if (formField.value && formField.value.id) {
|
||||
fieldValue = formField.value.id;
|
||||
@@ -143,22 +143,29 @@ export class WidgetVisibilityService {
|
||||
return fieldValue;
|
||||
}
|
||||
|
||||
private getObjectValue(field: FormFieldModel) {
|
||||
private getObjectValue(field: FormFieldModel, fieldId: string) {
|
||||
let value = '';
|
||||
if (field.value && field.value.name) {
|
||||
value = field.value.name;
|
||||
} else if (field.options) {
|
||||
let option = field.options.find(opt => opt.id === field.value);
|
||||
if (option) {
|
||||
value = option.name;
|
||||
} else {
|
||||
|
||||
value = field.value;
|
||||
value = this.getValueFromOption(fieldId, option);
|
||||
}
|
||||
}
|
||||
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 {
|
||||
let formattedFieldName = this.removeLabel(field, fieldToFind);
|
||||
return field.id ? field.id.toUpperCase() === formattedFieldName.toUpperCase() : false;
|
||||
|
Reference in New Issue
Block a user