Skip to main content

Hi

I have a text area in which i only want the user to be alllowed to enter only two rows.

Currently user can press enter and can go beyond 2 rows.

Hi,


 


This is possible using a script 


 


Add a data label to your view/form then check literal property and uncheck PreventXSS


Add the following script as an expression on the data label:


 


<script>
$('#TextAreaID').on('keydown keypress keyup',function(e){
if(e.keyCode == 8 || e.keyCode == 46){
return true;
}
var maxRowCount = $(this).attr("rows");
var lineCount = $(this).val().split('
').length;
if(e.keyCode == 13){
if(lineCount == maxRowCount){
return false;
} }
var jsElement = $(this)[0];
if(jsElement.clientHeight < jsElement.scrollHeight){
var text = $(this).val(); text= text.slice(0, -1); $(this).val(text);
return false;
} });
</script>

Source of the script here


Reply