From 71edf33f612d26fd9f51b5b5cfbb831adb87d017 Mon Sep 17 00:00:00 2001 From: roman Date: Thu, 25 Nov 2021 17:35:31 +0200 Subject: [PATCH 1/2] * removeFocus setFocus methods produce unhandled errors #45 fixed * onEnter method produce unhandled errors #19 fixed --- projects/ngx-dadata/src/lib/ngx-dadata.component.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/projects/ngx-dadata/src/lib/ngx-dadata.component.ts b/projects/ngx-dadata/src/lib/ngx-dadata.component.ts index fc675c3..54e000a 100644 --- a/projects/ngx-dadata/src/lib/ngx-dadata.component.ts +++ b/projects/ngx-dadata/src/lib/ngx-dadata.component.ts @@ -77,7 +77,7 @@ export class NgxDadataComponent implements OnInit, ControlValueAccessor, OnChang // @Output() selectedData = new EventEmitter(); // @Output() selectedString = new EventEmitter(); - @ViewChild('inputValue', { static: true }) inputValue: ElementRef; + @ViewChild('inputValue', {static: true}) inputValue: ElementRef; private inputString$ = new Subject(); @@ -182,6 +182,9 @@ export class NgxDadataComponent implements OnInit, ControlValueAccessor, OnChang onEnter(event: KeyboardEvent) { this.selectedSuggestion = this.data[this.currentFocus]; + if (!this.selectedSuggestion) { + return; + } this.inputValue.nativeElement.value = this.selectedSuggestion.value; this.data = []; this.currentFocus = -1; @@ -193,12 +196,18 @@ export class NgxDadataComponent implements OnInit, ControlValueAccessor, OnChang setFocus(id: number) { const activeEl = document.getElementById(id + 'item'); + if (!activeEl) { + return; + } this.r.addClass(activeEl, 'active'); } removeFocus(id: number) { if (id !== -1) { const activeEl = document.getElementById(id + 'item'); + if (!activeEl) { + return; + } this.r.removeClass(activeEl, 'active'); } } From c35bd93fc702fbbde606b0aaa546180dcfd80b55 Mon Sep 17 00:00:00 2001 From: roman Date: Thu, 25 Nov 2021 17:44:51 +0200 Subject: [PATCH 2/2] * spaces fixed --- projects/ngx-dadata/src/lib/ngx-dadata.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/ngx-dadata/src/lib/ngx-dadata.component.ts b/projects/ngx-dadata/src/lib/ngx-dadata.component.ts index 54e000a..988bbf1 100644 --- a/projects/ngx-dadata/src/lib/ngx-dadata.component.ts +++ b/projects/ngx-dadata/src/lib/ngx-dadata.component.ts @@ -77,7 +77,7 @@ export class NgxDadataComponent implements OnInit, ControlValueAccessor, OnChang // @Output() selectedData = new EventEmitter(); // @Output() selectedString = new EventEmitter(); - @ViewChild('inputValue', {static: true}) inputValue: ElementRef; + @ViewChild('inputValue', { static: true }) inputValue: ElementRef; private inputString$ = new Subject();