English 中文(简体)
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 html 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.





相关问题
xform data grid

I am using orbeon to process my xforms. I am attempting to create a data grid that I can use to copy and paste rows/columns of data from my clipboard (excel). Do you have any clue how I can implement ...

Connect Chiba xForm to a restful web service (exist db)

I need to read an xml instance from an exist db. I am attempting to connect chiba to a restful web service via the following command: <xf:model> <xf:instance id="data-instance" ...

ISML PAC to XForm Conversion

Are there any tools or write-ups that can help in converting ISML PACs to XForms? Does anyone have experience in such a conversion?

XForms: how to deal with instance data that changes?

At the moment I am working on an XForms application to mutate XML data. This data comes from a local XML file. The file is exported from another application in a static way and read into the ...

Client side XForms processing tools [closed]

What would be the best client side javascript based XForms processor? I m trying to migrate plugin (activeX) based Xforms processing solution to a javascript based client side processor. But the ...

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 ...

热门标签