angular-editor icon indicating copy to clipboard operation
angular-editor copied to clipboard

how to set maxlength of character

Open aravind-ui opened this issue 6 years ago • 7 comments

hi, Can anyone know how use the max-length and min-length.

aravind-ui avatar Jul 03 '19 12:07 aravind-ui

@aravind-ui Hi! What do you mean by max length of character?

kolkov avatar Jul 03 '19 14:07 kolkov

I know for me, since I would be saving the HTML in our database, it would be helpful to be able to set a max amount of characters (including the markup) that the end user can't go past.

spmorr01 avatar Jul 05 '19 18:07 spmorr01

you can also maintain char count using function ts file : descriptionCharCount(){ this.DescriptionDummyElement.innerHTML = this.desForm.value.description; this.totalDescriptionCount = this.descriptionDummyElement.innerText.length; this.totalDescriptionFormattedTextCount = this.desForm.value.description.length; if(this.totalDescriptionCount < 1) { this.desForm.patchValue({ description: "" }); } }

<angular-editor (keyup)="descriptionCharCount()"> </angular-editor>

cpratiksha avatar Oct 03 '19 10:10 cpratiksha

Waiting for this feature.

rajibhalder avatar May 03 '20 04:05 rajibhalder

Hi, Can anyone know how to use the max-length and min-length?

muruganklt avatar Nov 30 '21 07:11 muruganklt

Hi, any news about this feature ?

ior308 avatar Feb 09 '22 15:02 ior308

Try this. HTML

<span class="text-danger"
                    *ngIf="this.emailTemplateForm.controls?.description?.hasError('maxlengthError')">
                    Only 5000 characters allowed.
                  </span>

ts

InitialSetup(){
   this.emailTemplateForm = this._fb.group({
   	....
     description: new FormControl("",[Validators.required, this.editorMaxLength(5000)]),
     ........
   })
 }
 
 editorMaxLength(maxlength): ValidatorFn {
   return (control: AbstractControl): { [key: string]: any } => {
     var regex = /(<([^>]+)>)/ig;
     var value = control.value;
     var result = value.replace(regex, "");
     if (result.length > maxlength) {
       return { 'maxlengthError': true };
     }else{
       return null;
     }
   }
 }

muruganklt avatar Feb 10 '22 04:02 muruganklt