Input maxLength

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?

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.

1 Like

Oh crap! You meant in your view right?

Why not then try this:

maxlength={{myMaxLength}}

Where myMaxLength is defined somewhere in your TS?

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