From: joern turner wrote
Hello again,
Paul Miniato wrote:
Hi again,
Many types, as used in the xf:type attribute of the xf:bind
element do not allow empty strings in their data space.
At present this means that, if a data element with bind
constraints that specify types such as decimal or date is not
required, it is still not possible to leave the field completely
blank without getting an error.
The XForms spec at <
http://www.w3.org/TR/xforms/slice6.html#model-xformsconstraints >
doesn't really get into this issue of whether the
xf:required="false"
attribute should cause an empty string to be acceptable in this
field. But, I will point out that without this, many of these
types are useless when used with optional fields.
you've brilliantly summarized an issue which we also discussed on
the list some month ago with Sophie in context of
Schema2XFormsBuilder tool. - and as i have to state without
actually resolving the issue. as you've mentioned the spec isn't
really enlightening here - the handling of schema optional elements
isn't really specified.
part of the problem is surely Chiba itself not handling the Schema
types correctly. to be consistent with XML Schema IMO XForms should
explicitly require that optional (not required) elements are
initialized with their equivalent to the empty type e.g. '0' for
integer or some other specified default. at least this would
consistently setup the complete instance at once and avoid trouble
with optional elements becoming required through some calculation.
Cause Chiba simply uses strings here it's part of the problem by
now.
Nevertheless the spec leaves gaps here that have to be filled to
get a running system.
My initial expectation (and still my hope) is that
xf:required="false" should suppress any type checking if the
element is empty. What do you think of this?
this might be a solution. at least until we have a real Schema
support. (it's highest priority on our todo list)
other opinions around? please speak up.
Joern
(You might think that any explicit xf:constraint might also need
to be relaxed if the field is not required and blank, but this
can always be explicitly allowed for in the constraint XPath.)
Sample attached.
Thanks, Paul M
Paul Miniato Standard Forms Project < http://ecommerce.cucbc.com/
>
<<requiredIssue.xml>>
--------------------------------------------------------------
----------
<?xml version="1.0" encoding="ISO-8859-1"?> <html
xmlns="http://www.w3.org/2002/06/xhtml2"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:chiba="http://chiba.sourceforge.net/2003/08/xforms" >
<head> <xf:model id="model1"> <xf:submission id="submit1"
xf:action="http://localhost:8080/chiba-0.9.5/jsp/debug-instance.jsp"
xf:method="post" xf:replace="all"/>
<xf:instance> <top> <data1></data1> <data2></data2> </top>
</xf:instance>
<xf:bind id="data1" xf:nodeset="/top/data1" xf:type="decimal"
xf:required="true()"/> <xf:bind id="data2"
xf:nodeset="/top/data2" xf:type="decimal" xf:required="false()"/>
</xf:model> </head>
<body> <xf:group> <xf:input bind="data1"> <xf:label>Required
decimal</xf:label> <xf:alert>Required decimal alert</xf:alert>
</xf:input>
<xf:input bind="data2"> <xf:label>Optional decimal</xf:label>
<xf:alert>Optional decimal alert</xf:alert> </xf:input>
<xf:submit submission="submit1"> <xf:label>Test Submit</xf:label>
</xf:submit> </xf:group> </body> </html>