Create a Toggle Button InfoPath 2007
Author: mety Labels:: Create a Toggle Button InfoPath 2007What is a toggle button?A toggle button is a button, when clicked, makes itself or another control switch between two states: On and off. For example, you can use a toggle button to select a check box (the check box is in an on state) if it is deselected (the check box is in an off state) and deselect a check box if it is selected. A toggle button is ideal for when you have a group of check boxes which you want to simultaneously select or deselect as shown in Figure 1. The Select All Expenses button in Figure 1 is used as a toggle button to select all of the check boxes in the repeating table. The Deselect All Expenses button in Figure 2, which is the same button as in Figure 1 but which has a different label, is used as a toggle button to deselect all of the check boxes in the repeating table. Create a form template with controlsThis tutorial shows you how to create a button with which you can select or deselect check boxes in the first column of a repeating table on a form template. You can follow along or download the completed form template here. Create a new blank form template1. Launch Microsoft Office InfoPath. By default, InfoPath may open the Getting Started dialog box. If it does, click Design a Form Template. Otherwise, in InfoPath, on the File menu, click Design a Form Template. 2. On the Design a Form Template dialog box, select Form Template under the Design a new section, select Blank under the Based on section, and then click OK. Insert a repeating table control1. On the form template, place the cursor where you want to insert the repeating table. 2. If the Controls task pane is not visible, click More Controls on the Insert menu, or press ALT+I, C. 3. On the Controls task pane under Insert controls, click Repeating Table. 4. On the Insert Repeating Table dialog box, in the Number of columns text box, accept the default number of 3 columns, and then click OK. 5. The repeating table is created with a text box in each column. To convert the first text box to a Check Box control, right-click the text box, point to Change To on the shortcut menu, and then click Check Box. 6. Double-click the Check Box control to open its Properties dialog box. 7. On the Check Box Properties dialog box, select True/False (boolean) from the Data type drop-down list box, select 0 from the Value when cleared drop-down list box, select 1 from the Value when checked drop-down list box, and then click OK. 8. To convert the second text box to a Date Picker control, right-click the text box, point to Change To on the shortcut menu, and then click Date Picker. 9. Place the cursor in the second column of the first row and type the text Date. 10. Place the cursor in the third column of the first row and type the text Description. Insert a button control1. Place the cursor below the repeating table. On the Controls task pane under Insert controls, click Button. 2. Double-click the Button control to open its Properties dialog box. 3. On the Button Properties dialog box, type Toggle Check Boxes in the Label text box, and then click OK. The form template should resemble Figure 3. Add toggle functionality to the button controlTo add toggle functionality to the button, you must add the following two rules to the button: 1. A rule to check all of the check boxes in the repeating table if the check boxes are unchecked. 2. A rule to uncheck all of the check boxes in the repeating table if the check boxes are checked. Add a rule to select the check boxes in the repeating table1. Double-click the Button control to open its Properties dialog box. 2. On the Button Properties dialog box, click Rules. 3. On the Rules dialog box, click Add. 4. On the Rule dialog box, click Add Action. 5. On the Action dialog box, select Set a field's value from the Action drop-down list box. 6. On the Action dialog box, click the button behind the Field text box to open the Select a Field or Group dialog box. 7. On the Select a Field or Group dialog box, click the plus sign in front of group1 to expand it, click the plus sign in front of group2 to expand it, and select field1. The Select a Field or Group dialog box should resemble Figure 4. 8. On the Select a Field or Group dialog box, click OK. 9. On the Action dialog box, type 1 in the Value text box. The Action dialog box should resemble Figure 5. 10. On the Action dialog box, click OK. 11. Now you must create a condition for this rule to run only when the check box is deselected, so when the value of field1 is equal to 0. On the Rule dialog box, click Set Condition. 12. On the Condition dialog box, select Select a field or group from the first drop-down list box. 13. On the Select a Field or Group dialog box, click the plus sign in front of group1 to expand it, click the plus sign in front of group2 to expand it, select field1, and then click OK. 14. On the Condition dialog box, select is equal to from the second drop-down list box. 15. On the Condition dialog box, select "0" from the third drop-down list box, and then click OK. 16. On the Rule dialog box, select the Stop processing rules when this rule finishes check box to prevent any rules from running after the condition for this rule is met and the rule runs. 17. Click OK to close the Rule dialog box. Leave all other dialog boxes open. Add a rule to deselect the check boxes in the repeating table1. On the Rules dialog box, click Add. 2. On the Rule dialog box, click Add Action. 3. On the Action dialog box, select Set a field's value from the Action drop-down list box. 4. On the Action dialog box, click the button behind the Field text box to open the Select a Field or Group dialog box. 5. On the Select a Field or Group dialog box, click the plus sign in front of group1 to expand it, click the plus sign in front of group2 to expand it, select field1, and then click OK. 6. On the Action dialog box, type 0 in the Value text box, and then click OK. 7. Now you must create a condition for this rule to run only when the check box is selected, so when the value of field1 is equal to 1. On the Rule dialog box, click Set Condition. 8. On the Condition dialog box, select Select a field or group from the first drop-down list box. 9. On the Select a Field or Group dialog box, click the plus sign in front of group1 to expand it, click the plus sign in front of group2 to expand it, select field1, and then click OK. 10. On the Condition dialog box, select is equal to from the second drop-down list box. 11. On the Condition dialog box, select "1" from the third drop-down list box, and then click OK. 12. On the Rule dialog box, select the Stop processing rules when this rule finishes check box to prevent any rules from running after the condition for this rule is met and the rule runs. 13. Click OK to close the Rule dialog box. 14. Click OK to close the Rules dialog box. 15. Click OK to close the Button Properties dialog box. 16. To test your changes, click Preview on the Standard toolbar, or press CTRL+SHIFT+B. When you click the button, the check box is selected. When you click the button again, the check box is deselected. Add toggle functionality to the label of the button controlYou can take the toggle functionality a step further by adding functionality to switch between two labels for the button control whenever you click the button as shown in Figure 1 and Figure 2. You can define the label of a button control to be either static or dynamic. The text of a static label never changes, while the text of a dynamic label can change under certain conditions or when certain actions are taken. To make a label dynamic, you must use a hidden field as the source of the label and create rules to change the value of that hidden field. A hidden field is a field that is present in the data source of a form template, but not visible on any view of the form template. Because you only want to display text on a button and not show the text in a field on the form, you must use a hidden field to store the text. Add a hidden field to store the text for the label of the button1. If the Data Source task pane is not visible, click Data Source on the View menu. 2. On the Data Source task pane, select myFields, and then click Add a Field or Group under the Actions section. See Figure 6. 3. On the Add Field or Group dialog box, type buttonLabel in the Name text box, and type Select Check Boxes in the Default value text box. See Figure 7. 4. On the Add Field or Group dialog box, click OK. The buttonLabel field is now present in the data source of the form, but not visible on the form itself. Set the hidden field to be the source of the label of the button1. Double-click the Button control to open its Properties dialog box. 2. On the Button Properties dialog box, click the button behind the Label text box to open the Insert Formula dialog box. 3. On the Insert Formula dialog box, click Insert Field or Group. 4. On the Select a Field or Group dialog box, select buttonLabel, and then click OK. 5. On the Insert Formula dialog box, click OK. Add toggle functionality to the label of the button1. On the Button Properties dialog box, click Rules. 2. On the Rules dialog box, select the first rule, and then click Modify. 3. On the Rule dialog box, click Add Action. 4. On the Action dialog box, select Set a field's value from the Action drop-down list box. 5. On the Action dialog box, click the button behind the Field text box to open the Select a Field or Group dialog box. 6. On the Select a Field or Group dialog box, select buttonLabel, and then click OK. 7. On the Action dialog box, type Deselect Check Boxes in the Value text box, and then click OK. 8. On the Rule dialog box, click OK. 9. On the Rules dialog box, select the second rule, and then click Modify. 10. On the Rule dialog box, click Add Action. 11. On the Action dialog box, select Set a field's value from the Action drop-down list box. 12. On the Action dialog box, click the button behind the Field text box to open the Select a Field or Group dialog box. 13. On the Select a Field or Group dialog box, select buttonLabel, and then click OK. 14. On the Action dialog box, type Select Check Boxes in the Value text box, and then click OK. 15. On the Rule dialog box, click OK. 16. On the Rules dialog box, click OK. 17. On the Button Properties dialog box, click OK. 18. To test your changes, click Preview on the Standard toolbar, or press CTRL+SHIFT+B. When you click the button, the check box is selected and the text on the button changes to Deselect Check Boxes. When you click the button again, the check box is deselected and the text on the button changes to Select Check Boxes. |