InfoPath Tip: Working with radio buttons and check boxes
Indeed, working with InfoPath is easy but sometimes some tips
come in handy, specially when you are short on time.
We will see how you can control different sections in a form
using radio buttons. Consider this scenario. You have sections
in a form. Each section opens up by clicking a check box. There
are radio options in the form, option 1 and option 2. When user
selects option 1, checkbox 1 should be checked and section 1
should open. When user selects option 2, checkbox 2 should be
checked and section 2 should open. Similarly, when user selects
option 2, checkbox 1 should be unchecked and section 1 should
hide. When user selects option 1, checkbox 2 should be unchecked
and section 2 should hide. Fair enough! It seems easy but there
is a small catch. To check a checkbox, you set its value to
"True" or "1". To uncheck it, you set its value to "False" or
"0". Does this work? No. To uncheck a checkbox, you should set
its value to "" (blank). Setting it to "False" will not give
error but desired result will not be produced. The checkbox will
not be unchecked and hence related section will not hide. Also,
to set a value to "True", simply writing "True" in the value
will not work. You should use boolean() function. For example,
boolean("True") or boolean("False"). Another interesting thing
is, simply typing this formula in the value box will not work.
InfoPath will treat it as a text. InfoPath will put single
quotes around it and consider it text. Proper way is to use
1. This is how form with controls will look like:
Fig 1: Form
2. Add conditional formatting to Section 1 to hide it when
Checkbox 1 is checked.
Fig 2: Conditional formatting for Section 1
3. Add conditional formatting to Section 2 to hide it when
Checkbox 2 is checked.
4. Add rule to Option 1. By default, the value of Option button
1 is "1" and value of option button 2 is "2". Name rule "Open
Section1" and set condition:
Fig 3: Set condition for Rule "Open Section1"
5. After setting the condition, click "Add Action" button to add
action. In the "Field", select "Checkbox1" then click the "fx"
button to add formula.
Fig 4: Add Action
6. Use "Insert Function" button to add "boolean" function or
write it directly in the formula box. Click "Verify Formula"
button to verify the formula and then click "OK".
Fig 5: Add Formula
7. You need to add three more rules. Rules are shared between
both option buttons. Rules you set for any of the option buttons
work for both the buttons. Add second rule "Close Section 2".
Set following condition:
Fig 6: Set condition for rule "Close Section 2"
Add action for this rule. Select "Checkbox1" in "Field" and
leave the value blank. This will uncheck the "Checkbox1".
8. Add third rule "Open Section 2" to open section 2. Set
condition: Options is equal to "2" and add action: "Checkbox2"
has value "boolean("True")". Use technique described above to
add formula. Remember, typing formula manually will not set the
boolean value and will be considered as plain text by InfoPath.
9. Add fourth rule "Close Section 1". Add following condition:
Fig 7: Set condition for rule "Close Section 1"
Add following action:
Fig 8: Add action
Select "Checkbox1" in "Field" and leave value blank. This will
uncheck the "Checkbox1". Remember sections are bound with these
check boxes. Checking Checkbox1 will show section 1 and
unchecking it will hide section 1. Similarly, checking Checkbox2
will show section 2 and unchecking it will hide section 2.
That's it. The tip, in a nutshell, was that you should set the
value of the checkbox to "blank" to uncheck it. Setting it to
"False" will not uncheck it.