question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Set Focus on ng-select by Code

See original GitHub issue

I create 2 ng-select on 1 page like below

<ng-select [items]="dataOffice" bindLabel="office_name" bindValue="office_code" placeholder="- Select -" #office="ngModel" (keydown.enter)="keytab($event, 'customer')" name="office"> </ng-select>

<ng-select [items]="dataCustomer" bindLabel="customer_name" bindValue="customer_code" placeholder="- Select -" #customer="ngModel" id="customer" name="customer"> </ng-select>

and then i set event (keydown.enter) on office so when i press enter the focus will change to customer

keytab(event, target) { let nextElm = this.renderer2.selectRootElement('#' + targetElm); nextElm.focus(); }

Its work on input or normal select, but when on ng-select the focus not changed to customer dropdown and the dropdown become blank.

Can you advice?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
varnastadeuscommented, Oct 26, 2018

there is no need, latest version has method focus. #select.focus()

1reaction
BruneXXcommented, Oct 26, 2018

If it helps someone, I’ve managed to set focus on ng-select input element this way:

this.ngSelectInput.filterInput.nativeElement.focus();

Read more comments on GitHub >

github_iconTop Results From Across the Web

focus for ng-select not working Angular 5 - Stack Overflow
this works fine for me, @ViewChild('ngSelect') ngSelect: NgSelectComponent; ngAfterViewInit() { if (this.autofocus) { setTimeout(() ...
Read more >
Ng Select Focus Issue - StackBlitz
ng-select focus issue. Programmatical focus should open dropdown-panel. ... import { NgSelectComponent } from '@ng-select/. ng-select';. @Component({.
Read more >
ng-select How to programmatically set a value
I miss this opportunity this.optionsSelect = [ { value: '1', label: 'Option 1' }, { value: '2', label: 'Option 2', SELECTED: true },...
Read more >
@ng-select/ng-select - npm
@ng-select/ng-select. TypeScript icon, indicating that this package has built-in type declarations · Readme · Code Beta · 1 Dependency · 466 ...
Read more >
Angular ng-focus Directive - W3Schools
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found