viewer.measureHeightAdded by IBM on August 8, 2013 | Version 1 (Original)
|Dynamically changes the height of a field to fit the text entered by a user. The height of the field can be measured in either pixels or characters.
This function should be used as part of a size or itemlocation options, to allow items to be dynamically sized based on the amount of text in those items. The viewer.measureHeight function must be used in conjunction with the toggle function or be triggered by the event model.
viewer.measureHeight(units, item, scrollvert)
Table 1. viewer.measureHeight parameters
|units||String||Determines whether height is measured in chars or pixels.|
|item||Reference string||Optional. References the item you want to measure. If no item is specified, the item containing the measureHeight function will be measured.|
|scrollvert||String||Optional. Determines whether a scrollbar should be taken into consideration when measuring the height of a field. Used only if you have a dynamically-added vertical scrollbar that only appears when the field has the focus. If this parameter is used, its setting must be always.|
Returns Returns a number representing the height in lines or pixels.
Example The example under sets the height of the field to either the value returned by the viewer.measureHeight function, or to the minimum height required for two lines of text, whichever is greater. The calculation is based on the default 8pt Arial font, which means that the minimum height for two lines is 38 pixels. Other fonts and font sizes have different heights. The field resizes itself when the user tabs out of the field or moves the cursor to another item on the form.
In this example, the value "38" is the height (in pixels) that the field is set to when it is empty. This value must be determined based on the font size used and how many blank lines of text you want to show when the field is empty.
Character values for height should be used to set the second element of the size option. For example:
<field sid = "description_FIELD">
<height compute="(toggle(value) == '1') and
(viewer.measureHeight('pixels') > '38') ?
viewer.measureHeight('pixels') : '38'"></height>
Using the size option to set the height of an item does not always allow for an exact fit. In some cases the item may be slightly larger than the text displayed, depending on the font and font size used.
<height compute="(toggle(value) == '1') ?
viewer.measureHeight('chars') : '1'"></height>
- You must use the event model, such as keypress or mouseover events or the toggle function, to trigger the viewer.measureHeight function.
- The viewer.measureHeight function should be used only with field, label, or box.
- To have viewer.measureHeight run automatically, when the form opens, toggle the function off of the value of the global.global.activated option. This option will switch to on when the form is opened.