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