How to modify the “on” value and caption of a repeated Check Box using JavaScript in LiveCycle Designer


If you are building dynamically a list of check boxes in Adobe’s LiveCycle Designer, you will have to be able to dynamically change the “on” value for each of the check boxes or else all the checked items will have the same value (default is 1).

Usually if you want some check boxes, you just drag them from Object Library and set the On Value with the value you want, but there are situations when you want to build dynamically a list of check boxes by repeating one of them.

Regular check boxes in LiveCycle Designer

Regular check boxes in LiveCycle Designer

Repeated check boxes in LiveCycle Designer

Repeated check boxes in LiveCycle Designer

To create a dynamic list of check boxes you have to use a Table (only Tables and Subforms can be set as repeaters) and repeat the row that contains the check box. Here is some example code:

for (var i = 0; i < countItems; i++) {
    // for each checkbox you want to add, create a new instance of the Row
    var rowInstance = form1.page2.Table1._Row1.addInstance(true);

    var myCheckBox = rowInstance.CheckBox1;

    // set the "on" value for the added checkbox
    myCheckBox.items.nodes.item(0).value = theDesiredCode;

    //set the caption of the added checkbox
    myCheckBox.caption.value.text.value = theDesiredCaption;
}

To better understand the code, take a look at the XML source for the repeated checkbox:

   <field name="CheckBox1" w="1.19in" h="0.236222in">
      <ui>
         <checkButton>
            <border>
               <edge stroke="lowered"/>
               <fill/>
            </border>
         </checkButton>
      </ui>
      <font typeface="Myriad Pro"/>
      <margin leftInset="1mm" rightInset="1mm"/>
      <para vAlign="middle"/>
      <value>
         <text>0</text>
      </value>
<caption placement="right" reserve="21.226mm">
         <para vAlign="middle"/>
         <value>
            <text>theDesiredCaption</text>
         </value>
      </caption>

      <items>
         <text>theDesiredCode</text>
         <text>0</text>
      </items>
      <bind match="none"/>
      <border>
         <edge>
            <color/>
         </edge>
         <corner thickness="0.1778mm"/>
      </border>
   </field>

Adobe LiveCycle Designer known restriction:
When you insert a new check box into your form, the default values (one and zero) are set in the XML as so the code above does not work when you want to change to a value other than integer. You have to change them to by modifying directly the XML, or by typing “dummy text” in the field for “on value” and change it back to 1. This will change the XML elements from 1 to 1, as shown in the XML examples below.

<field name="CheckBox1">
...
	<items>
		<integer>1</integer>
		<integer>0</integer>
		<integer>2</integer>
	</items>
...
</field>
Default XML source for a check box
<field name="CheckBox1">
...
	<items>
		<text>1</text>
		<text>0</text>
	</items>
...
</field>
Updated XML source to include strings

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s