You are viewing limited content. For full access, please sign in.

Question

Question

Adjusting height of textarea field in a table under classic forms

asked on June 4 Show version history

I am executing the attached javascript to adjust the height of textarea fields in an inquiry form.  The code works fine for standalone textarea fields, but always returns zero for the scrollHeight of textarea fields in a table.  Any insights would be appreciated.

$(document).on("onloadlookupfinished", function() {
//  $(':hidden').removeClass("hidden");
  $('[readonly]').prop('tabindex', -1);

// Adjust height of large text fields
  $("textarea").each(function (index, element) { // does not work in review steps table - Later
	const holdElem = document.getElementById(this.id);
    let compHeight = holdElem.scrollHeight;
    console.log(this.scrollHeight);
    this.style.height = "auto";
    compHeight = this.scrollHeight;
    console.log(this.scrollHeight);
    if (compHeight > 58)
      compHeight = compHeight + 2
    else
      compHeight = 60;
    this.style.height = compHeight+"px";
    console.log("resize ",index, " ", this.id, " ", this.scrollHeight, " ", compHeight);
  });
 });

 

0 0

Replies

replied on June 4

I haven't tested this, but I would assume it has to do with the DOM elements not existing when the lookup event is being fired. You can try using the change event instead:

$(document).on('change', 'textarea', (event) => {
   const holdElem = event.target;
   // Rest of code when each textarea changes 
   // no longer need to loop through each textarea
});

 

0 0
replied on June 4 Show version history

This functionality is happening within the onloadlookupfinished event handler, so the table should be completed at that point.  I tried it to be certain and there was no difference.  Thanks anyway.

0 0
replied on June 4

Oh wait, I think I missed a comment in your code "// does not work in review steps table - Later". Is the problem that the code isn't working on subsequent process steps but works on the first form that loads the data?

0 0
replied on June 4

No, this form is a single step inquiry.  It executes depending on a parameter value.

The function works fine on textarea elements that are "standalone".  The function fails on textarea elements that are in a collection.  It fails because the value of scrollHeight is always zero when referenced in the function.  However, the value of scrollHeight is accurate (non-zero) when inspecting the element in the browser after the form has been displayed.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.