From b052770d30689b1881c885e439177cbfb6d0f910 Mon Sep 17 00:00:00 2001 From: Federico Piana - SpeederX Date: Sun, 24 Nov 2024 21:04:56 +0100 Subject: [PATCH] Fix autocomplete updateOn blur on select (#16805) --- src/app/components/autocomplete/autocomplete.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/app/components/autocomplete/autocomplete.ts b/src/app/components/autocomplete/autocomplete.ts index 119043a597..2671f1fd5e 100755 --- a/src/app/components/autocomplete/autocomplete.ts +++ b/src/app/components/autocomplete/autocomplete.ts @@ -1209,7 +1209,11 @@ export class AutoComplete implements AfterViewChecked, AfterContentInit, OnDestr this.dirty = false; this.focused = false; this.focusedOptionIndex.set(-1); - this.onModelTouched(); + /** triggered only if user can input freely text + * Later on it must set touched also onSelect */ + if(!this.forceSelection){ + this.onModelTouched(); + } this.onBlur.emit(event); } @@ -1446,6 +1450,9 @@ export class AutoComplete implements AfterViewChecked, AfterContentInit, OnDestr this.updateModel(value); } + /** triggers model touched to update FormControl + * value in case updateOn is set to "blur" */ + this.onModelTouched(); this.onSelect.emit({ originalEvent: event, value: option }); isHide && this.hide(true);