As a reference, the most similar question already asked is: https://stackoverflow.com/questions/8667849/making-xforms-enforce-the-constraint-and-type-model-item-properties-only-when-fi The difference is that I cannot use the 'relevant' property since I do want the field to be visible and accessible.
I'm attempting to make an XForms form that has the following properties:
The trouble now is that even though the field has no data in it, the constraint is still enforced (i.e. even though it is not marked as 'required').
I have taken a look at the XForms 1.1 specification, however it does not seem to describe how the properties 'required' and 'constraint' should interact.
The only option I see, is to add a part to the constraint such that an empty value is allowed. e.g.:
. = '' or <actual-constraint>
However, I don't like this. It feels like a workaround to add this to every such field.
Is there any other way to express that non-required fields should not need to match the constraint for that field? (Am I missing something?)
In XForms 1.1, required
serves two purposes:
The latter is described in 4.3.3 The xforms-revalidate Event.
An instance node is valid if and only if the following conditions hold:
And one of the conditions is:
the value is non-empty if the required model item property is true
So it is a logical and
between all aspects that impact validation.
I can see how things could have been different, e.g. saying required="false()"
could disable the rest of the validation. However that's not the approach XForms is taking.
Based on this there is nothing wrong checking for emptiness as part of the constraint.
XForms 2.0 might add custom XPath functions, which might help with reuse of logic:
<bind ref="information" constraint="my:constraint(.)">
Also, if the constraint can be expressed with a type, you may be able to use one of the schema types in the XForms namespace, which allow empty values to be valid. For instance xforms:double
considered the empty string and 42
to be valid values, but not gaga
.