简体   繁体   中英

How to focus into an input box from PrimeNG autocomplete?

I want to focus into inputbox after PrimeNg autocomplete onSelect event click.

<p-autoComplete [(ngModel)]="itemIdAuto" name="itemIdAuto1" #itemIdAuto1="ngModel" size="15" 
[suggestions]="filteredItemIdAutoSingle" (completeMethod)= "itemIdAutoComplete($event)" field="name" 
(onSelect)="itemOnSelect(itemIdAuto)" placeholder= "Select Item Name" [minLength]="1"></p-autoComplete>

<input type="number" autocomplete="off" style="font-size:12px" class="form-control" name="qty"
[(ngModel)]="model.qty" #qty="ngModel">

TypeScript:

import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';

export class GridFormComponent implements OnInit {

constructor() {
}

ngOnInit() {
}
@ViewChild('aForm') aForm: ElementRef;

itemOnSelect(item) {        
    this.aForm.nativeElement['qty'].focus();
    }
}

look at this link stackblitz

Hope it will help you,let me know if have any query

thanks

I am adding another answer as per your last comment look at below link and let me know if you found any issue.

one more thing to focus on element i have used jquery so please kindly keep note it.

stackblitz

thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM