How to get an XForm to display a checkbox?

自古美人都是妖i 提交于 2019-12-13 18:18:14

问题


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.

  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" />
    



回答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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!