[AAE-11480] - Fix required error is displayed for a non required drop… (#8021)

* [AAE-11480] - Fix required error is displayed for a non required dropdown

* Use alias for async pipe instead of subscribing 2 times
This commit is contained in:
Ardit Domi
2022-12-01 14:11:20 +00:00
committed by GitHub
parent e5489363a1
commit e343de5c13
5 changed files with 112 additions and 19 deletions

View File

@@ -531,7 +531,7 @@ describe('FormFieldModel', () => {
expect(field.value).toBe(false);
});
it('should delete empty dropdown value from the form values', () => {
it('should set the value as null for a dropdown field that has the None value selected', () => {
const form = new FormModel();
const field = new FormFieldModel(form, {
id: 'dropdown-1',
@@ -539,10 +539,13 @@ describe('FormFieldModel', () => {
});
field.value = 'empty';
expect(form.values['dropdown-1']).toBe(undefined);
expect(form.values['dropdown-1']).toBe(null);
field.value = '';
expect(form.values['dropdown-1']).toBe(undefined);
expect(form.values['dropdown-1']).toBe(null);
field.value = undefined;
expect(form.values['dropdown-1']).toBe(null);
});
it('should update form with dropdown value', () => {

View File

@@ -361,6 +361,12 @@ export class FormFieldModel extends FormWidgetModel {
switch (this.type) {
case FormFieldTypes.DROPDOWN:
if (!this.value) {
this.form.values[this.id] = null;
break;
}
/*
This is needed due to Activiti reading dropdown values as string
but saving back as object: { id: <id>, name: <name> }
@@ -372,7 +378,7 @@ export class FormFieldModel extends FormWidgetModel {
if (typeof this.value === 'string') {
if (this.value === 'empty' || this.value === '') {
delete this.form.values[this.id];
this.form.values[this.id] = null;
break;
}