The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How can I change the number of rows in a text input box using a client script?

HugoFirst
Kilo Sage

I have a text input box which can contain several lines of text.

My requirement is to display the text without scrolling.

So I need to adjust the number of rows in the textbox to match the number of lines in the text.

I know how to determine the # lines, I just need to know how to set the number of rows in the text box.

FWIW: I have a script which can adjust the height in pixels of the field.   But this only works for a fixed font size.

I'd like to have the text input box resized to show all the text regardless of font-size.

If it helps, here's the script to resize the height in pixels:

Script to resize the height of a text input box in pixels

function onLoad() {

    //Type appropriate comment here, and begin script below

  var text = g_form.getValue('change_request.u_release_version');

  var height = text.split(/\n/).length * 20;

  if ( height < 19 ) { height = 20; }

      g_form.getControl('change_request.u_release_version').style.height = height + 'px';

}

1 ACCEPTED SOLUTION

HugoFirst
Kilo Sage

FWIW:   I have a solution which works to meet my requirement, though the actual implementation is to set the height of the textarea element and not the rows.   A co-worker who is well versed in jQuery worked this out for me.


This works even if I change the font-size.



Note: If you try this script, be sure you fit the context:


      The variable is defined in a change request, is a textarea type and is named u_release_version.


      The variable is displayed on the change task in it's entirety ( without scroll bars ).


      The solution is an onLoad script on the change_task form/table.



Here is the script to resize the textarea box when the form loads:



function onLoad() {


// Using jQuery to find the scroll height and set the height to display all text in Release/Version box



var $j_custom = jQuery.noConflict(true);


var textarea = $j_custom('textarea#change_task\\.change_request\\.u_release_version');


var height = textarea[0].scrollHeight;


textarea.css({'height':height + 20});


}


View solution in original post

1 REPLY 1

HugoFirst
Kilo Sage

FWIW:   I have a solution which works to meet my requirement, though the actual implementation is to set the height of the textarea element and not the rows.   A co-worker who is well versed in jQuery worked this out for me.


This works even if I change the font-size.



Note: If you try this script, be sure you fit the context:


      The variable is defined in a change request, is a textarea type and is named u_release_version.


      The variable is displayed on the change task in it's entirety ( without scroll bars ).


      The solution is an onLoad script on the change_task form/table.



Here is the script to resize the textarea box when the form loads:



function onLoad() {


// Using jQuery to find the scroll height and set the height to display all text in Release/Version box



var $j_custom = jQuery.noConflict(true);


var textarea = $j_custom('textarea#change_task\\.change_request\\.u_release_version');


var height = textarea[0].scrollHeight;


textarea.css({'height':height + 20});


}