Skip to main content

Hi,

 

Is there a scripty/data label way of increasing the height of the text area as each new line is reached?

 

I followed this thread: http://community.k2.com/t5/K2-blackpearl/Dynamic-increase-height-of-Text-Area-control/ta-p/91051

but the height increases each time a character is entered, which ends up with a huge gap at the bottom of the text area.

Also, the first solution only works if you click outside of the text area, which is pointless, as the user isn't likely to do that.

 

Is there a way to have the text area add a line to the height each time a new line starts?

 

Thanks

Hi Sharpharp1,


 


I know you can add new line once the user hit Enter using the following script


 


<script>
$(document).on('keyup', 'textarea', function(e) {
if (e.which == 13 || e.keyCode == 13) {
var rowAttr = $(this).attr('rows');
rowAttr = +rowAttr + +1;
$(this).attr('rows', rowAttr);
}});
</script>

Let me know if this helps


 


 


 


Hi Mustafa,

 

Just tried this and it doesn't work.

 

1) Added it to an Expression:

2) Put script tags round your script.

3) On control change, transfer your script.

 

Ran form, nothing happens when press enter


Hi Sharpharp1,


 


Apologies I tested the script on the browser console and forgot to add some ';'


 


Updated script in my previous reply


 


this should work if you add it as an expression on a datalabel


Thanks Mustafa,

 


Reply