Search code examples
orbeon

Orbeon forms - repeated section field validation


I have form like this: https://demo.orbeon.com/demo/fr/orbeon/builder/edit/f34f17613d9dbce14bcdf1219b1a7a6babaeebe2

I want to add validation like this:

  • only one field 'yes/no' in this section can have selected value 'yes' at the same time
  • validation message should appear only under the fields with selected value 'yes'

Should I create some action, that iterate over all 'yes/no' fields, check their value and raise an error if detect above situation?

My main problem is how to iterate over all 'yes/no' fields and detect this situation.


Solution

  • Assuming you name your field yes-no, then the following expression will do it:

    string() = 'false' or
    count(//yes-no[string() = 'true']) <= 1
    

    With this expression you're saying that an answer is valid if either:

    • it is "No", as we don't have any limit on those, or
    • there only one "Yes", or less.

    And for more on that string() = 'true' business, see Testing on a Yes No Answer field.

    At most one Yes