Change the Checked and Cleared Values of a Check Box - Greg Collins
in

InfoPath Dev

This Blog

Syndication

Greg Collins

Change the Checked and Cleared Values of a Check Box

Changing the checked and cleared values of a check box bound to a field in the main data source is easily accomplished using the built-in UI on the Data tab of the Check Box Properties dialog box. Changing the checked and cleared values of a check box bound to a field in a secondary data source requires manually modifying the view .xsl file.

When you add a data connection to an .xml file, InfoPath makes no attempt to decipher data types for each field and attribute but simply assigns everything the string data type. Although this can be inconvenient, it can be fixed.

When you insert a Check Box into the view for a field with the string data type, whether from the main data source or a secondary data source, InfoPath will always use yes for the checked value and no for the cleared value (as shown in Figure 1).


Figure 1. For string data type fields, InfoPath uses yes for the checked value and no for the cleared value.

When you insert a Check Box into the view for a field with the Boolean data type, whether from the main data source or a secondary data source, InfoPath will always use true for the checked value and false for the cleared value (as shown in Figure 2).


Figure 2. For Boolean data type fields, InfoPath uses true for the checked value and false for the cleared value.

Figures 1 and 2 illustrate that a check box bound to a field in a secondary data source does not provide the ability to change the checked and cleared values, as these options are grayed out. If your form is expecting these values to be something other than yes/no or true/false, you will need to modify the view .xsl file to change these values.

In this task we will create a form that includes a secondary data source with two fields intended to hold Boolean values, for which InfoPath will create a schema using the string data type. We will modify the view .xsl file to use 1 and 0 as the checked and cleared values of the first check box, and use Present and Absent as the checked and cleared values of the second check box. Let's start by creating the secondary data source.

Create the secondary data source:

Copy the following code into a text editor, and then save the file as Booleans.xml. This file will be used as a secondary data source in our form.

<?xml version="1.0" encoding="UTF-8"?>
<Booleans>
    <ItemAvailable/>
    <StudentAttendance/>
</Booleans>

Add the secondary data source to a form:

  1. Design a new blank form.
  2. Choose Data Connections from the Tools menu, and then click Add.
  3. In the Data Connection Wizard, select Receive Data, and then click Next.
  4. Select XML Document, and then click Next.
  5. Click Browse, locate and select the Booleans.xml file, click Open, and then click Next.
  6. Click Finish, click Yes, and then click Close.

Insert the two check boxes into the view:

  1. Open the Data Source task pane.
  2. Select the Booleans secondary data source.
  3. Right-click ItemsAvailable, click Check Box, and then press Enter.
  4. Right-click StudentAttendance, and then click Check Box.

Modify the view .xsl file:

  1. Choose Extract Form Files from the File menu.
  2. Select a location to save your extracted form files to, and then click OK.
  3. Close InfoPath to release the lock it places on your form files.
  4. Using a text editor, open your view .xsl file.

Change the checked and cleared values for the first check box:

  1. Search for the text xd:offValue="no" to locate the input element that represents your first Check Box control.
  2. Make the following changes to the first input element:

xd:offValue="no" xd:onValue="yes"

to:

xd:offValue="0" xd:onValue="1"

  1. Search for the text &quot;yes, and then make the following change:

ItemAvailable=&quot;yes&quot;

to:

ItemAvailable=&quot;1&quot;

Change the checked and cleared values for the second check box:

  1. Search for the text xd:offValue="no" to locate the input element that represents your second Check Box control.
  2. Make the following changes to the second input element:

xd:offValue="no" xd:onValue="yes"

to:

xd:offValue="Absent" xd:onValue="Present"

  1. Search for the text &quot;yes, and then make the following change:

StudentAttendance=&quot;yes&quot;

to:

StudentAttendance=&quot;Present&quot;

Review your changes:

  1. Save the view .xsl file, and then close the text editor.
  2. Reopen your form template by right-clicking the manifest.xsf file and choosing Design.

Now when examine the Check Box Properties dialog boxes for the two check boxes, you will find your altered checked and cleared values, as shown in Figure 3. Provided that you do not delete the modified check box and insert a new one, the updated values will be persisted even through a rebinding.


Figure 3. The checked and cleared values have been manually modified.

©2005 Greg Collins. All rights reserved. Licensed to Autonomy Systems, LLC for display on InfoPathDev.com.

Published Jun 21 2005, 04:42 PM by Greg Collins
Filed under:

Comments

No Comments
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.