diff --git a/projects/aca-content/folder-rules/src/rule-details/conditions/rule-simple-condition.ui-component.html b/projects/aca-content/folder-rules/src/rule-details/conditions/rule-simple-condition.ui-component.html index 918311c79e..ec171eb5f0 100644 --- a/projects/aca-content/folder-rules/src/rule-details/conditions/rule-simple-condition.ui-component.html +++ b/projects/aca-content/folder-rules/src/rule-details/conditions/rule-simple-condition.ui-component.html @@ -33,11 +33,14 @@ matInput [matAutocomplete]="auto" formControlName="parameter" + (focusout)="autoSelectValidOption()" data-automation-id="auto-complete-input-field" /> diff --git a/projects/aca-content/folder-rules/src/rule-details/conditions/rule-simple-condition.ui-component.spec.ts b/projects/aca-content/folder-rules/src/rule-details/conditions/rule-simple-condition.ui-component.spec.ts index 3ca42f3610..3a11aa6ef6 100644 --- a/projects/aca-content/folder-rules/src/rule-details/conditions/rule-simple-condition.ui-component.spec.ts +++ b/projects/aca-content/folder-rules/src/rule-details/conditions/rule-simple-condition.ui-component.spec.ts @@ -333,4 +333,17 @@ describe('RuleSimpleConditionUiComponent', () => { expect(displayValue).toBe('category/path/1/FakeCategory1'); discardPeriodicTasks(); })); + + it('should automatically select first category when user focuses out of parameter form field with category option selected', fakeAsync(() => { + spyOn(categoryService, 'searchCategories').and.returnValue(of(fakeCategoriesList)); + fixture.detectChanges(); + changeMatSelectValue('field-select', 'category'); + tick(500); + const autoCompleteInputField = getByDataAutomationId('auto-complete-input-field')?.nativeElement; + autoCompleteInputField.value = 'FakeCat'; + autoCompleteInputField.dispatchEvent(new Event('focusout')); + const parameterValue = fixture.componentInstance.form.get('parameter').value; + expect(parameterValue).toEqual(fakeCategoriesList.list.entries[0].entry.id); + discardPeriodicTasks(); + })); }); diff --git a/projects/aca-content/folder-rules/src/rule-details/conditions/rule-simple-condition.ui-component.ts b/projects/aca-content/folder-rules/src/rule-details/conditions/rule-simple-condition.ui-component.ts index 2c07c2dec8..1c4692212a 100644 --- a/projects/aca-content/folder-rules/src/rule-details/conditions/rule-simple-condition.ui-component.ts +++ b/projects/aca-content/folder-rules/src/rule-details/conditions/rule-simple-condition.ui-component.ts @@ -243,4 +243,12 @@ export class RuleSimpleConditionUiComponent implements OnInit, ControlValueAcces autoCompleteDisplayFunction: (id: string) => string = (optionValue) => optionValue && this.autoCompleteOptions ? this.autoCompleteOptions.find((option) => option.value === optionValue)?.displayLabel : optionValue; + + autoSelectValidOption() { + const currentValue = this.parameterControl.value; + const isValidValueSelected = !!this.autoCompleteOptions?.find((option) => option.value === currentValue); + if (!isValidValueSelected) { + this.parameterControl.setValue(this.autoCompleteOptions?.[0].value); + } + } }