#NgModel with maxlength bytes count

7 messages · Page 1 of 1 (latest)

quaint salmon
#

Hello, I come back to you, I don't have much experience with Angular, I search a lot on the internet, but I can't find what I'm looking for, I would like my maxlenght to depend on my count of bytes, I don't have I have no choice but to use bytes at work, and I need to prevent the user from exceeding 4000 bytes, I tried to modify the maxlength each time the ngModel changes to recheck the number and modify the maxlength following but it doesn't work, I leave my Stack if anyone has an idea.

https://stackblitz.com/edit/angular-11-material-reactive-starter-4xuqpv?file=src/app/material-input/material-input.component.ts

Starter project for Angular apps that exports to the Angular CLI

random kernel
#

create a custom validator

quaint salmon
#

Ok I didn't dig on that side, thanks for the lead anyway

random kernel
#

you can either create a custom directive to block the input after a certain length and/or create a custom validator on your formControl to trigger an error

quaint salmon
#

one last little detail, can I make a custom directive or validator and implement it afterwards? I would like it to be integrated into my custom component directly

random kernel
#

shouldn't be a pb