问题
I want to validate the size of the phone number field based on the selection made in the Phone Type field. Cell numbers should be 10 in size, Home and work numbers should be 11 in size. How would I write the constraint expression in Orbeon Form Builder. I tried using if in the constraint field, but was unsuccessful.
Thank you for your help!
回答1:
Let's say you have two controls: a phone type and a phone number.
- Create the phone type control, for instance as a drop-down or radio buttons. Give it a name, clicking on the cogwheel to open Edit Control Details. Say that name is
phone-type
. You will will refer later to the value selected by users as$phone-type
. - Edit the items and keep in mind the value you assign to each item. The value is what you will use later, while the label is what is displayed to end users in the form. Say the values are
work
andmobile
. Create a single line control (text field), click on the red exclamation mark to open the Edit Validation Properties dialog, and there, under Constraint, write:
string-length(.) = (if ($phone-type = 'work') then 11 else 10)
来源:https://stackoverflow.com/questions/6323506/write-constraint-to-validate-a-field-based-on-the-value-entered-in-another-field