Issue
When entering a multi-line text (using multiple ‘Enters’) into a text field that has a defined maximum character limit, the system displays a character count indicating that the input is within the allowed limit. However, when the user attempts to submit the form, the following error is displayed:
ORA-12899 value too large for column string (actual: string, maximum: string)
https://docs.oracle.com/en/error-help/db/ora-12899/?r=26ai
Steps to reproduce
-
Configure the Text Area Field with 'Max characters' limit.
-
Add input into the Text Area field.
-
Check the characters count displayed.
-
Verify that character count is different in the DB.
-
Click Submit.
Root Cause
Database is counting 'Enter' as two characters. For Pega, ‘Enter’ is counted as one character and for some standards it is ‘Carriage Return + Line Feed’ (two characters) as in the database.
Workaround
Perform the following method as a workaround:
Increase the size of column on database side using the below script. The following script helps in considering the Enter Key as two characters in client side which will fix the discrepancy.
<script>
if(pega.control.ITextArea) {
pega.control.ITextArea.prototype.keydown = function(event) {
var eventEle = event.target;
var tempValue = eventEle.value.replace(/\n/g,"\r\n");
var charMaxValue = eventEle.getAttribute("maxLength");
if(charMaxValue){
charMaxValue = parseInt(charMaxValue);
var keyCode = event.keyCode;
if((keyCode == 13 && (tempValue.length + 2) > charMaxValue) || (keyCode != 8 && (tempValue.length + 1) > charMaxValue)) {
event.preventDefault();
}
}
};
pega.control.ITextArea.prototype.updateTextAndCounter = function(eventEle) {
if(eventEle.nodeName.toUpperCase() == "TEXTAREA") {
var charMaxValue = eventEle.getAttribute("maxLength");
var tempValue = eventEle.value.replace(/\n/g,"\r\n");
if(charMaxValue){
charMaxValue = parseInt(charMaxValue);
var isMicrosoftEdge = navigator.userAgent.match(/Edge/ig);
if(tempValue.length > charMaxValue && (!("maxLength" in document.createElement("TEXTAREA")) || isMicrosoftEdge )) {
if (eventEle.value.length > tempValue.length) {
eventEle.value = eventEle.value.substring(0,charMaxValue + (eventEle.value.length - tempValue.length));
} else {
eventEle.value = eventEle.value.substring(0,charMaxValue);
}
this.valueReset = true;
}
eventEle.value = tempValue;
}
if(eventEle.getAttribute("updateCounter") == "true") {
var counterSpan = document.getElementById(eventEle.id+"_counter");
if(counterSpan){
counterSpan.innerHTML = ((charMaxValue - tempValue.length) < 0 ? 0 :(charMaxValue - tempValue.length));
}
}
}
};
}</script>
Related Content
-
Search for CRLF in MDN Web Docs
-
Search for ORA-12899 in Oracle Help center