How to validate the count from more than one object on the form

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to validate the count from more than one object on the form

mepknapp
In Form Builder - I have two check box areas.  I want to count(*) how many items have been checked and make sure that it does not exceed 3 items....if so then give validation error.

A variation on this (and the REAL issue) is that I need to:
1) count the number of items in checkbox area A
2) count the number of 'checked'  checkboxes in area A
3) subtract (2) from (1)
THEN
4) count the number of 'checked' checkboxes in area B
THEN
5) add (3) and (4)
6) make sure (5) is not greater than 3 items and if so give validation error

Help is GREATLY appreciated!!!!
Reply | Threaded
Open this post in threaded view
|

Re: How to validate the count from more than one object on the form

Alessandro  Vernet
Administrator
Mary,

If you have a selection control named gaga, you can get:

- The number of selected items with: count(xxf:split($gaga))
- The total number of selectable items with: count(xxf:itemset('gaga-control', 'xml')/itemset/choices/item)

Because of the way things are evaluated, the value of the second expression will be 0 right after the form is loaded, but will become "correct" as soon as a value is changed, which should be fine for the purpose of validation.

I hope this helps,

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet