import { Component , AfterViewInit , ViewChild , ElementRef } from '@angular/core' ; import { FormControl , Validators } from '@angular/forms' ; import { ModalDialogParams } from '@nativescript/angular' ; import { showKeyboard } from '../../shared/misc' ; @ Component ( { selector : 'bc-payee-modal' , templateUrl : './payee-modal.component.html' , styleUrls : [ './payee-modal.component.scss' ] , } ) export class PayeeModalComponent implements AfterViewInit { @ ViewChild ( 'payeeField' , { static : false } ) payeeField : ElementRef ; payee : FormControl ; payees : string [ ] ; constructor ( private modalParams ) { this . payee = new FormControl ( '' , Validators . required ) ; this . payees = modalParams . context ; } ngAfterViewInit ( ) { showKeyboard ( this . payeeField . nativeElement ) ; } filterPayees ( ) { const regexp = new RegExp ( this . payee . value , 'iu' ) ; const filtered = this . modalParams . context . filter ( ( payee ) => { return payee . search ( regexp ) !== - 1 ; } ) . sort ( ) ; this . payees = filtered ; } onPayeeTap ( payee ) { if ( payee === this . payee . value ) { this . select ( ) ; } else { this . payee . setValue ( payee ) ; this . payeeField . nativeElement . android . setSelection ( payee . length ) ; } } select ( ) { this . modalParams . closeCallback ( this . payee . value ) ; } }