Input maxLength


#1

How can i set a dynamic maxLength to a <ion-input> ?
I tryed it with maxlengt=_maxLength which didn’t work but maxlength=10 works.
Also tryed [attr.maxlength]= and [maxlength]= both don’t worked for me…

Isn’t it possible to set the normal maxlength of the base input?
Or is there a work around which works with objects?


#2

Hi,

Use Validators, i.e. :

this.myForm = myFormBuilder.group({
      my_field: ['', [
        Validators.required,
        Validators.minLength(6),
        Validators.maxLength(200)
      ]]
});

Then replace dynamically in your code. That should work.


#3

Oh crap! You meant in your view right?

Why not then try this:

maxlength={{myMaxLength}}

Where myMaxLength is defined somewhere in your TS?


#4

yeah i meant in my view :stuck_out_tongue:
so i tryed it before but tryed it again now and still not working with
maxlength={{mymaxlength}}

Seems like its just ignored somehow if its not a fix value…

Looks like i need some validating code