Stefan Cameron on Forms
Building intelligent forms using Adobe LiveCycle Designer

oneOfChild Scripting Property

Sometimes it’s necessary to access the properties contained within a field object’s UI property. For example, you might want to highlight only the content area (the value portion as opposed to the caption portion) of a text field. The problem with doing that is that you need to access the UI property’s one-of property in order to get at the Border object that it contains. The "ui.{one-of property}.border" object controls the appearance of the field’s content area. (Tip: It’s also the object that’s affected when you use the Appearance property on the Field tab in the Object palette).

If you were to look at the XFA specification supported by Designer 7.1, you would find, on page 664, that the UI element contains various one-of properties (which describe a set of properties from which only one may be specified at any given time) which vary depending on the type of field you’ve created on your form. For example, if it’s a text field, it has a

field.ui.#textField

property whereas a drop down list would have a

field.ui.#choiceList

property.

Based on the various definitions of XFA fields, you would have to write the following script to change a text field‘s content area color (shown here in FormCalc):

$.ui.#textField.border.fill.color = "255,0,0"

But what about a drop down list? Because it uses a different UI one-of property ("choiceList" instead of "textField"), you would have to write the following script (shown here in JavaScript) to change its content area color:

this.ui.resolveNode("#choiceList").border.fill.color.value = "255,0,0"

This is all fine as long as you know the type of object on which the script will be executed but what if you wanted to change the content area color of all fields on your form? You might decide to define multiple arrays that contain references to text fields, numeric fields, etc. (one array for each type) but that wouldn’t be very practical because you would have to remember to keep that list up-to-date for every change you made to your form.

A much easier way to do this is simply by using the oneOfChild scripting property: It’s designed to return a reference to the one-of property that has been specified in the Object Model on the object on which it is used. In other words, if you used it on a text field‘s UI property, it would represent the "#textField" property whereas on a drop down list, it would represent the "#choiceList" property.

If we put this in practice, it means you could use the following script to change the content area color of any field object you find on your form (shown here in FormCalc):

FieldObject.ui.oneOfChild.border.fill.color = "255,0,0"

where "FieldObject" would be a variable holding a reference to a field object on your form.

Of course, the use of the oneOfChild property also works because the Border property is common to all UI one-of properties. There are some cases where some properties are specific to a certain "UI type" (like the "#choiceList.textEntry" property). In those cases, you may need to verify that you are, in fact, attempting to access those properties on the right kind of UI one-of property or else you’ll get a scripting runtime exception.


Posted by Stefan Cameron on November 9th, 2006
Filed under Scripting
Both comments and pings are currently closed.

4 Responses to “oneOfChild Scripting Property”

  1. Marijn Sponselee on January 11th, 2007

    Hi Stefan,
    I’m sure you know, but it’s not mentioned here: the oneOfChild property is already available in Designer 7.0 see XFA spec 2.2 and it works like a charm.

    Kind regards, Marijn Sponselee

  2. fursten on December 19th, 2008

    Hello Stefan,

    I have one question for you about this topic:

    What about changing the appearance property of an object (for instance, a dropdown) in runtime? As far as I understood, this property points to a processing instruction like this:

    Thank you.

  3. fursten on December 19th, 2008

    sorry, like this: templateDesigner StyleID aped2

  4. Stefan Cameron on December 20th, 2008

    fursten,

    The processing instruction inside the field’s //ui/{oneOfChild}/border node is just there to help Designer easily remember what the appearance property’s setting is when it’s set to one of the presets in the property’s drop down list. In reality, the “Object palette > Field tab > Appearance property” is a combination of the elements under the //ui/{oneOfChild}/border node which specify border edges and corners as well as fill color and style.

    If you want to set the “appearance” at runtime using script, you would use the oneOfChild property to get to the <border> node inside the field’s <ui> element and you would go from there. For example, to set the fill colour of a text field’s content area, you would do this:

    TextField1.ui.oneOfChild.border.fill.color.value = "255,0,0"; // red

    I actually have a post on setting various fill colors if you’re interested: Field Background Color Fill.