Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Retrieve Height of an expandable text field

Avatar

Former Community Member
Hi,



I have a table in a dynamic interactive PDF form. When the user enters text into a text field of the table, the field can expand over multiple lines. I want to know how I can retrieve the height of the expanded field so that I can resize other elements in the table such that they are kept in line with the expanded text box. It appears the height property (h) is always zero, and the maxH is also zero.



Any help appreciated.



Phil Rimmington
5 Replies

Avatar

Former Community Member
It's possible to retrieve this information but you have to use the xfa.layout model instead of the xfa.form model in order to do so.



By retrieving the h or maxH property of an object by doing



this.h

this.maxH


means that you're accessing these properties from the xfa.form model which
defines the objects on the form. This model, however, doesn't give you layout information such as the resulting number of pages in a dynamic form once data has been merged into it or, in your case, the actual/current height of a field which expands in height to fit its content.



The layout information must be retrieved from the xfa.layout model using methods that take references to the object whose layout information is sought.



In this case, we want the actual/current height of a field which is height-expandable. We therefore need to use the xfa.layout.h method as follows, in JavaScript:



xfa.layout.h(TextField1, "mm");


The first parameter takes a reference to the field in question and the second takes a string which identifies the unit of measure in which you want the height returned (the default is points (pt)). You can use "cm", "mm", "in", "px", "pt", etc.



Note that you shouldn't use xfa.layout methods unless xfa.layout.ready returns
true or else the information you get may be out-of-sync with how the form actually ends-up being laid-out.



I've attached a sample form which has a multi-lined, height-expandable text field and a button. Clicking the button will produce a message box containing the actual/current height of the text field.



Stefan

Adobe Systems

Avatar

Former Community Member
Stefan,



I trust you are keeping well. Thanks for your reply - its done the trick.



Regards

Phil Rimmington

Oxley Park Solutions Limited

Avatar

Former Community Member
Does this work in dynamic interactive forms? It returns undefined if placed on a validate event or on an exit event.

Avatar

Former Community Member
Of course! If the function is returning "undefined" instead of a measurement, it's possible that you're calling it too soon. Since the layout is the last thing that occurs after a change is made to a form, the Validate and Exit events would be too soon.



You might want to try checking the



xfa.layout.ready


property prior to calling any of the xfa.layout functions. This read-only property is set to
true only once the layout process is complete and scripting tasks can start.



You can also place your script in the Layout:Ready event. This event occurs every time the layout process completes (which is every time a change occurs to the form). I should warn you, however, that the script you place in that event may get executed more often than you expect therefore you may wish to use Form Variables (or something similar) as "guards" to make sure the script only executes when it should.



I've attached a second sample which displays the message box with the field's height in the Layout:Ready event. Note the one guard which is not to display the message box unless the field is filled. Also note that the event fires just before the display is updated with the changes to the layout which were triggered by the field's change in value.



Stefan

Adobe Systems

Avatar

Former Community Member
How do you get the height of the expandable text field if it goes onto a second or third page...it only returns the height of the text box on the first page