[AAE-8554] - Fix linked dropdown values are displayed but not submitted (#7590)

* [AAE-8554] - Fix dropdown values are displayed but not submitted

* Make eslint allow ternary
This commit is contained in:
arditdomi 2022-04-21 17:25:38 +01:00 committed by GitHub
parent 3d19b79699
commit 6fcac9f5f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 8 deletions

View File

@ -89,7 +89,14 @@
"rxjs/no-subject-unsubscribe": "error", "rxjs/no-subject-unsubscribe": "error",
"rxjs/no-subject-value": "error", "rxjs/no-subject-value": "error",
"rxjs/no-unsafe-takeuntil": "error", "rxjs/no-unsafe-takeuntil": "error",
"unicorn/filename-case": "error" "unicorn/filename-case": "error",
"@typescript-eslint/no-unused-expressions": [
"error",
{
"allowShortCircuit": true,
"allowTernary": true
}
]
} }
}, },
{ {

View File

@ -592,13 +592,15 @@ describe('DropdownCloudWidgetComponent', () => {
entries: mockConditionalEntries entries: mockConditionalEntries
} }
}); });
const updateFormSpy = spyOn(widget.field, 'updateForm'); const updateFormSpy = spyOn(widget.field, 'updateForm').and.callThrough();
const mockParentDropdown = { id: 'parentDropdown', value: 'IT' }; const mockParentDropdown = { id: 'parentDropdown', value: 'IT', validate: (): boolean => true };
spyOn(widget.field.form, 'getFormFields').and.returnValue([mockParentDropdown]); spyOn(widget.field.form, 'getFormFields').and.returnValue([mockParentDropdown]);
widget.field.value = 'MI';
fixture.detectChanges(); fixture.detectChanges();
expect(updateFormSpy).toHaveBeenCalled(); expect(updateFormSpy).toHaveBeenCalled();
expect(widget.field.options).toEqual(mockConditionalEntries[1].options); expect(widget.field.options).toEqual(mockConditionalEntries[1].options);
expect(widget.field.form.values).toEqual({ 'child-dropdown-id': { id: 'MI', name: 'MILAN' }});
}); });
it('should load the selection of a rest type linked dropdown', () => { it('should load the selection of a rest type linked dropdown', () => {

View File

@ -135,11 +135,7 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI
private parentValueChanged(value: string) { private parentValueChanged(value: string) {
if (value && !this.isDefaultValue(value)) { if (value && !this.isDefaultValue(value)) {
if (this.isValidRestType()) { this.isValidRestType() ? this.persistFieldOptionsFromRestApi() : this.persistFieldOptionsFromManualList(value);
this.persistFieldOptionsFromRestApi();
} else {
this.persistFieldOptionsFromManualList(value);
}
} else if (this.isDefaultValue(value)) { } else if (this.isDefaultValue(value)) {
this.resetRestApiErrorMessage(); this.resetRestApiErrorMessage();
this.addDefaultOption(); this.addDefaultOption();
@ -165,6 +161,7 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI
if (ruleEntry.key === value) { if (ruleEntry.key === value) {
this.field.options = ruleEntry.options; this.field.options = ruleEntry.options;
this.resetInvalidValue(); this.resetInvalidValue();
this.field.updateForm();
} }
}); });
} }