Max lenght TextField


#1

is there any way to set the max length to a TextField? something like this :

<TextField hint="Escribe aquí" maxLenght="10" editable="true"></TextField>


#2

There are related answers in github issues:



#3

Thanks habibkazemi for the reply, but i need a solution to Nativescript/Angular and i readed those answers but the “solutions” are not working for me at angular…

Any solution for angular?


#4

for example to convert the below code to angular:

var phoneField = view.getViewById(page,'phoneField');
var fArray = [];
fArray[0] = new android.text.InputFilter.LengthFilter(10);
phoneField.android.setFilters(fArray);

for angular u can use ViewChild add an id to your xml :
<TextField id="txtfield" hint="Escribe aquí" maxLenght="10" editable="true"></TextField>

@ViewChild('txtfield') phoneField
then use ngAfterViewInit like this:

ngAfterViewInit(){
      var fArray = [];
      fArray[0] = new android.text.InputFilter.LengthFilter(10);
      phoneField.android.setFilters(fArray);
}

but this might have problems so you can use (loaded) event instead read more about it here: