问题
I seem to be having problems getting a xform
to display a check box -- instead it is displaying a text area. All my other items are working correctly, I just can't seem to get this one to work.
This is the code inside my model:
<takeMoneyOff type="xs:boolean"/>
// close the my structure
// close the instance
<xf:bind id="takeMoneyOff" nodeset="/xForm/takeMoneyOff"/>
// close the model
And the item this is all referring to for display is:
<xf:input ref="takeMoneyOff" class="takeMoneyOffClass">
<xf:label>Take Money Off? </xf:label>
</xf:input>
回答1:
You don't mention which XForms implementation(s) you are targeting, but assuming that it is / they are fully conformant, you have two options.
If you want to specify the type in the instance data, as your example code indicates, you need the type attribute to be in the XML schema instance namespace. So, if you've declared the namespace prefix
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
, your instance datum would need to look like this:<takeMoneyOff xsi:type="xs:boolean" />
Alternatively, if the instance data is coming from an external source and you're not in control of it, then you can place a type attribute on the bind element itself instead (it should not be in the xsi namespace in this case):
<xf:bind id="takeMoneyOff" nodeset="/xForm/takeMoneyOff" type="xs:boolean" />
回答2:
You can also use <xforms:select>
, which will store a value or blank:
<xf:select ref="takeMoneyOff" class="takeMoneyOffClass">
<xf:label>Take Money Off? </xf:label>
<xf:item>
<xf:label>Yes</xf:label>
<xf:value>true</xf:value>
</xf:item>
</xf:select1>
With the appropriate bind, you could even store "false" when a blank appears:
<xf:bind id="takeMoneyOff" nodeset="/xForm/takeMoneyOff"
calculate="choose(. = 'true', ., 'false')"
readonly="false()"/>
来源:https://stackoverflow.com/questions/1851956/how-to-get-an-xform-to-display-a-checkbox