[7094] Fix empty save people groups (#7137)

* fix empty save people groups

* fix
This commit is contained in:
Eugenio Romano
2021-07-01 12:36:13 +02:00
committed by GitHub
parent 94aa8aec35
commit 05c3ed01d7
2 changed files with 29 additions and 3 deletions

View File

@@ -612,6 +612,31 @@ describe('FormFieldModel', () => {
expect(form.values['dropdown_field'].name).toEqual('Option 1');
});
it('should parse and resolve people null value as null', () => {
const field = new FormFieldModel(new FormModel(), {
type: FormFieldTypes.PEOPLE,
value: null
});
field.updateForm();
expect(field.value).toBe(null);
});
it('should parse and resolve people undefined value as null', () => {
const field = new FormFieldModel(new FormModel(), {
fieldType: 'HeaderFieldtype',
id: 'people_field',
name: 'people',
type: FormFieldTypes.PEOPLE,
value: undefined
});
field.updateForm();
expect(field.value).toBe(null);
});
describe('variables', () => {
let form: FormModel;
@@ -680,5 +705,6 @@ describe('FormFieldModel', () => {
expect(field.value).toBe('default hello');
});
});
});

View File

@@ -268,7 +268,7 @@ export class FormFieldModel extends FormWidgetModel {
}
parseValue(json: any): any {
let value = json.hasOwnProperty('value') ? json.value : null;
let value = json.hasOwnProperty('value') && json.value !== undefined ? json.value : null;
/*
This is needed due to Activiti issue related to reading dropdown values as value string
@@ -408,10 +408,10 @@ export class FormFieldModel extends FormWidgetModel {
this.form.values[this.id] = (this.value !== null && this.value !== undefined) ? this.value : false;
break;
case FormFieldTypes.PEOPLE:
this.form.values[this.id] = (this.value !== null && this.value !== undefined) ? this.value : [];
this.form.values[this.id] = this.value ? this.value : null;
break;
case FormFieldTypes.FUNCTIONAL_GROUP:
this.form.values[this.id] = (this.value !== null && this.value !== undefined) ? this.value : [];
this.form.values[this.id] = this.value ? this.value : null;
break;
default:
if (!FormFieldTypes.isReadOnlyType(this.type) && !this.isInvalidFieldType(this.type)) {