Search code examples
xpathorbeonxforms

Validation rules for optional fields


How can an input field made with the Orbeon form builder be optional but still have validation rules? As soon as I add a validation rule, the field is invalid, even though i set it to optional (not required).

Example for a number that should be either empty or between 0 and 100:

<fr:number id="control-1-control" bind="control-1-bind"></fr:number>

With this binding:

<xf:bind id="control-1-bind" ref="control-1" name="control-1"
    type="xf:decimal" constraint=". ge 0 and . le 100"/>
</xf:bind>

How can I specifically make this optional? I tried changing my constraint to . eq '' or . ge 0 and . le 100 but this does not work... What can I do to allow an empty value?


Solution

  • I agree: it would make sense for all optional and empty fields to be consistently valid in all cases. However, in following with the XForms spec, this isn't the case right now. This being said, we have an RFE for doing this by default in the context of forms created by Form Builder.

    For now you can do it yourself as part of the constraint, by adding:

    xxf:trim() = '' or (. ge 0 and . le 100)