Expand my Community achievements bar.

How to get the dimensions (h & w) of dynamic objects

Avatar

Level 2

Hi,

Is there any way to get the dimensions (h & w) of dynamic objects (such as subform, or text field) via scripting?

To get way I was looking for, I tried using "object.h" or "object.w" in various events timings (i.e., @ initialize, form:ready and layout:ready) but I always get the result as "0".

If someone there knows a better way to place (event) the code or have different approach, I do appreciate it.

BR,

Yasser    

8 Replies

Avatar

Level 7

Hi,

This is covered in the F1 Help material. Search for "w scripting method" and "h scripting method".

Good luck!

Stephen

Avatar

Level 2

Hi Stephen,

Thanks for the reply.

My question is about getting the dimension of a suform that expand its height dynamically based on the adding more subforms, for example!

For example if you have a subform call mySubForm and if its high is "5cm", then if you run the following script:

          xfa.host.messageBox("The height of my subform is: " + mySubform.h);

Will return "The height of my subform is: 5cm" only if the "Expand to fit" property is not checked.

Once the "Expand to fit" property is checked, then the answer will be "The height of my subform is: 0cm".

It seems that this behavior is mentioned across all objects that expands/shrinks dynamically based on it's content.

Now, my question still valid; Is there any way to know the height/width of dynamically sized object at runtime?

BR,

Yasser

Avatar

Level 7

Hi Yasser,

I believe that you are trying to use h to take a measurement--and I believe that h is only used to assign a value. It may be returning the minH or maxH or 0, depending--but what you are doing with h is assinging 0 to the property h.

h Determines the height of a given form design object.when used this way (copied from the F1 Help):

Reference_Syntax.h( OBJECT param1 [, STRING param2 [, INTEGER param3 ] ] )

param1

The fully qualified reference syntax expression of one of the following  container XML Form Object Model objects: area,  contentArea, draw, field, pageArea, subform.

param2 (Optional)

A string representing the unit type of the return value. If left blank, the  default unit type is points.

param3 (Optional)

An integer representing a zero-based index value indicating the content area  in which you want to obtain the object's height. If left blank, the default  value is 0.

This parameter allows you to calculate the height of an object that is  distributed across multiple content areas, such as pages. For example, if you  want to find the height of a subform object that spans multiple content areas,  you would use this parameter to enumerate the height of the subform in each of  the content areas and add the totals together.

The example given:

// Returns the height of a single instance of TextField1

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

// Calculates the height of Subform1 across two content areas and displays

// the total in a message box.

     var iHeight = xfa.layout.h(Subform1,"in",0) + xfa.layout.h(Subform1,"in",1);

     xfa.host.messageBox(iHeight);

I played around with it a little and couldn't get it to work--but I think this is the right direction. I'm not sure what event is used--it may be layout:ready.

Good luck,

Stephen

Avatar

Level 2

Hi Stephen,

Great, it seems that this is the direction to go...

Really appreciate your help.

BR,

Yasser

Avatar

Level 2

Thank you Stephen,

I was also struggling on how to do that (spent the past days trying to get it to work actually) and it was that simple

Avatar

Level 1

Hi Yanip,

You have got the solution for this issue? Can you please explain me. I want to get the height of a text field 'A' which has expand to fit property or the height of the subform which contains that text field 'A'(subform is set to "auto fit") . My requirement is to assign this text field 'A' height to another checkbox field. I want to have the same height for both text field and checkbox field after that text field 'A' is dynamically expanded.

Thanks ,

Viji

Avatar

Level 10

The determine the dimensions of an object use the xfa.layout pseudo model methods h() and w().

xfa.layout.h(Table1, "in");    //returns the height of Table1 in inch

xfa.layout.w(Textfield, "mm");    //returns the width of Table1 in millimeters