开发者

How to get an XForm to display a checkbox?

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>


You don't mention which XForms implementation(s) you are targeting, but assuming that it is / they are fully conformant, you have two options.

  1. 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" />
    
  2. 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" />
    


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()"/>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜