[AAE-11654] Fix default option being selectable when parent dropdown … (#8146)

* [AAE-11654] Fix default option being selectable when parent dropdown has no option selected

* [AAE-11654] Remove comment
This commit is contained in:
Diogo Bastos 2023-01-31 15:44:31 +00:00 committed by GitHub
parent 0ab39e28fd
commit 1f450c0593
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 11 deletions

View File

@ -501,10 +501,7 @@ describe('DropdownCloudWidgetComponent', () => {
fixture.detectChanges();
await openSelect('child-dropdown-id');
const defaultOption: any = fixture.debugElement.query(By.css('[id="empty"]'));
expect(widget.field.options).toEqual([{ id: 'empty', name: 'Choose one...' }]);
expect(defaultOption.context.value).toBe(undefined);
expect(defaultOption.context.viewValue).toBe('Choose one...');
expect(widget.field.options).toEqual([]);
});
it('should fetch the options from a rest url for a linked dropdown', async () => {
@ -631,10 +628,7 @@ describe('DropdownCloudWidgetComponent', () => {
fixture.detectChanges();
await openSelect('child-dropdown-id');
const defaultOption: any = fixture.debugElement.query(By.css('[id="empty"]'));
expect(widget.field.options).toEqual([{ id: 'empty', name: 'Choose one...' }]);
expect(defaultOption.context.value).toBe(undefined);
expect(defaultOption.context.viewValue).toBe('Choose one...');
expect(widget.field.options).toEqual([]);
});
describe('Manual - On parent value changes (chain)', () => {

View File

@ -138,7 +138,7 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI
this.isValidRestType() ? this.persistFieldOptionsFromRestApi() : this.persistFieldOptionsFromManualList(value);
} else if (this.isNoneValueSelected(value)) {
this.resetRestApiErrorMessage();
this.addDefaultOption();
this.resetOptions();
this.resetInvalidValue();
} else {
this.field.options = [];
@ -196,8 +196,8 @@ export class DropdownCloudWidgetComponent extends WidgetComponent implements OnI
return !!this.field.rule.entries.length;
}
private addDefaultOption() {
this.field.options = [DEFAULT_OPTION];
private resetOptions() {
this.field.options = [];
this.updateOptions();
}