Wednesday, August 27, 2014

Looking for at least one checked checkbox in Multiple-Selection List Box groups using X-Path in InfoPath


In a scenario involving multiple groups of Multiple-Selection List Boxes where I needed to check and see if at least one checkbox was checked in an InfoPath form, I used a Calculated Field to display a message if no checkboxes were checked. Checking for at least one box checked can be accomplished by using the following X-Path expression:

substring("Text to show if no checkboxes selected", 1, (not(boolean(xdMath:Eval(dfs:dataFields/my:SharePointListItem_RW/my:ListBox1/Value[. != ""], "."))) and
not(boolean(xdMath:Eval(dfs:dataFields/my:SharePointListItem_RW/my:ListBox2/Value[. != ""], "."))) and
not(boolean(xdMath:Eval(dfs:dataFields/my:SharePointListItem_RW/my:ListBox3/Value[. != ""], ".")))) *
string-length("Text to show if no checkboxes selected"))

The condition evaluates to True (1) if no boxes are checked, False (0) if any box is checked. These 1 or 0 values are multiplied by the length of the text and serve as the third parameter in the substring function, determining the length of the substring.