Default Values in XForms Input
I have an XForm that has certain fields that may often be left blank (optional street address). Is there is technique to set a default value for that field, preferably a space (I am running into weird formatting issues with CSS). The h开发者_JAVA技巧tml form way of value=""
doesn't work, neither does setting a default value in the XML schema.
EXAMPLE:
<xforms:input ref="clientaddress/streetaddress2" model="model_inventory" >
<xforms:label>Street Address (Line 2)</xforms:label>
Leaving this field blank results in <streetaddress2/>
in the resulting xml document
I want
<streetaddress> </streetaddress>
Are you saying that you would like to set the value of all the fields in your instance that are blank to having a space? Assuming you have a static instance, you can add the following to your model:
<xforms:setvalue ev:event="xforms-model-construct-done"
xxforms:iterate="//*[empty(*) and string() = '']" ref="."> </xforms:setvalue>
Note that this uses the xxforms:iterate
extension of Orbeon Forms (documented here). If you are using another XForms implementation, you might want to check the documentation of that implementation to see if they provide a similar extension.
(This being said, I am curious as to why you need to have a space in the "empty" fields. Could that be a sign of a problem somewhere else?)
The easiest way to set default value in XForms is the instance:
<xforms:instance>
<data>
<clientaddress>
<streetaddress> </streetaddress>
</clientaddress>
</data>
</xforms:instance>
You said, that you tried to set default value in schema, but I'm not sure that it works as you expected. Schema can be used for validation, but I don't know if any XForms engine uses schema's default values.
精彩评论