Skip to main content

This content has been archived and is no longer being updated. Links may not function; however, this content may be relevant to outdated versions of the product.

Support Article

Textarea with character limit trims the end characters



On configuring a TextArea control with a character counter, and adding text in between after the limit is reached, results in trimming characters at the end of the text. The characters just entered are not trimmed.

Error Messages

Not Applicable

Steps to Reproduce

  1. Create a TextArea with a character limit, for example 50 characters. 
  2. Deploy the hotfix, HFix-37047.
  3. Access the TextArea and input 50 characters including New Line characters. 
  4. Enter additional characters in the beginning or in the middle of the TextArea.

Root Cause

A defect in Pegasystems’ code or rules. The browser behavior is overridden.


Perform the following local-change:

Add the below code. <script> 
if(pega && pega.control&& pega.control.ITextArea){ 
pega.control.ITextArea.prototype.updateTextAndCounter = function(eventEle) { 
// Internet Explorer 6-11 
var isIE = /*@[email protected]*/false || !!document.documentMode
if(eventEle.nodeName.toUpperCase() == "TEXTAREA") { 
var charMaxValue = eventEle.getAttribute("maxLength"); 
var charMaxValue = eventEle.getAttribute("charMaxValue"); 

/* BUG-89515:In IE quirks mode new line is interpreted as \r\n *&nbsp;
var tempValue = eventEle.value.replace(/\r/g,""); 
if(navigator.userAgent.lastIndexOf('Chrome/') > -1 || isIE){ 
var newLines = tempValue.match(/(\r\n|\n|\r)/g); 
var addition = 0; 
if (newLines != null) { 
addition = newLines.length

charMaxValue = parseInt(charMaxValue); 
//if(tempValue.length > charMaxValue && !("maxLength" in document.createElement("TEXTAREA"))) { 
/* If eventEle.value > tempValue.length substring should consider the difeerence in length *&nbsp;

/* BUG-205290: Fixed issue with remaining characters in IE *&nbsp;
var code =event ?(event.keyCode ? event.keyCode : event.which):""; 
if((charMaxValue- tempValue.length- addition)<0){ 

if (code == 13 && (charMaxValue- tempValue.length- addition)==-2 ) { 
eventEle.value = eventEle.value.substring(0,charMaxValue + (eventEle.value.length - tempValue.length-addition+1)); 
addition= addition-2 
} else if (code == 13 && (charMaxValue- tempValue.length- addition)==-1 ) { 
eventEle.value = eventEle.value.substring(0,charMaxValue + (eventEle.value.length - tempValue.length-addition)); 
addition= addition-2 
}else if(code=="" || code==91|| code==144){ 
addition= addition-2 
eventEle.value = eventEle.value.substring(0,charMaxValue + (eventEle.value.length - tempValue.length-addition)); 

else { 
eventEle.value = eventEle.value.substring(0,charMaxValue + (eventEle.value.length - tempValue.length- addition)); 

this.valueReset = true; 

if(eventEle.getAttribute("updateCounter") == "true") { 
var counterSpan = document.getElementById("_counter"); 
if(navigator.userAgent.lastIndexOf('Chrome/') > -1 || isIE){ 

counterSpan.innerHTML = ((charMaxValue - tempValue.length - addition)<0 ? 0 :(charMaxValue - tempValue.length - addition))+""; 
} else { 

counterSpan.innerHTML = ((charMaxValue - tempValue.length)<0 ? 0 :(charMaxValue - tempValue.length))+""; 


}, 300); 


Published April 16, 2018 - Updated October 8, 2020

Was this useful?

0% found this useful

Have a question? Get answers now.

Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.

Did you find this content helpful?

Want to help us improve this content?

We'd prefer it if you saw us at our best.

Pega Community has detected you are using a browser which may prevent you from experiencing the site as intended. To improve your experience, please update your browser.

Close Deprecation Notice
Contact us