[AAE-7010] - Fix nested linked dropdowns are not reset (#7463)

* [AAE-7010] - Fix nested linked dropdowns are not reset

* Rebase

* Reset rest in case value is not part of the options

* Update failing unit test due to form field changes
This commit is contained in:
arditdomi
2022-01-24 13:57:22 +00:00
committed by GitHub
parent bfe2961473
commit e98fd2db0c
4 changed files with 108 additions and 25 deletions

View File

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

View File

@@ -293,17 +293,14 @@ export class FormFieldModel extends FormWidgetModel {
if (json.type === FormFieldTypes.DROPDOWN) {
if (json.options) {
const options = <FormFieldOption[]> json.options || [];
if (options.length > 0) {
if (json.hasEmptyValue) {
const emptyOption = json.options[0];
if (value === '' || value === emptyOption.id || value === emptyOption.name) {
value = emptyOption.id;
}
} else {
if (value?.id && value?.name) {
value = value.id;
}
if (json.hasEmptyValue) {
const emptyOption = json.options[0];
if (value === '' || value === emptyOption.id || value === emptyOption.name) {
value = emptyOption.id;
}
} else {
if (value?.id && value?.name) {
value = value.id;
}
}
}
@@ -371,7 +368,7 @@ export class FormFieldModel extends FormWidgetModel {
if (typeof this.value === 'string') {
if (this.value === 'empty' || this.value === '') {
this.form.values[this.id] = {};
delete this.form.values[this.id];
break;
}