如何创建带有“是"/“否"值而不是“真"/“假"值的复选框项目? [英] How to create checkbox item resulting with 'yes'/'no' values instead of 'true'/'false'?

查看:53
本文介绍了如何创建带有“是"/“否"值而不是“真"/“假"值的复选框项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,希望这只是我缺乏 XForms 的经验.我需要为定义为枚举是"/否"的数据创建复选框项.基本上它只是布尔值,但有另一对值.我已经能够做的是一些基本有效但需要模型中的额外数据节点的事情:

I've got a problem and hope it's only my lack of experience in XForms. I need to create checkbox item for data that is defined as an enumeration 'Yes'/'No'. Basically it's just boolean value but with another pair of values. What I've already been able to do is something that basically works but need extra data node in model:

<xhtml:html xmlns:xforms="http://www.w3.org/2002/xforms"
    xmlns:f="http://orbeon.org/oxf/xml/formatting"
    xmlns:xhtml="http://www.w3.org/1999/xhtml"
    xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
    xmlns:ev="http://www.w3.org/2001/xml-events"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    >

    <xhtml:head>
        <xforms:model xmlns:xforms="http://www.w3.org/2002/xforms"
                xmlns:xs="http://www.w3.org/2001/XMLSchema" id="main-model">
          <xforms:instance id="instance">
            <main>
              <Boolean>true</Boolean>
              <YesNo>Yes</YesNo>
            </main>
          </xforms:instance>
          <xforms:bind ref="Boolean" type="xsd:boolean" />
          <xforms:bind ref="YesNo" constraint=". = 'Yes' or . = 'No'" />
        </xforms:model>
    </xhtml:head>
    <xhtml:body>
      <xforms:input ref="instance('instance')/Boolean">
        <xforms:label>Boolean: </xforms:label>
        <xforms:action ev:event="xforms-value-changed">
          <xforms:setvalue ref="instance('instance')/YesNo" value="if ( instance('instance')/Boolean = 'true' ) then 'Yes' else 'No'" />
        </xforms:action>
      </xforms:input>
      <br/>
      <xforms:output ref="instance('instance')/Boolean">
        <xforms:label>Boolean:</xforms:label>
      </xforms:output>
      <br/>
      <br/>
      <xforms:select ref="instance('instance')/YesNo" appearance="full">
        <xforms:label>Yes/No: </xforms:label>
        <xforms:item>
          <xforms:label></xforms:label>
          <xforms:value>Yes</xforms:value>
        </xforms:item>
        <xforms:action ev:event="xforms-value-changed">
          <xforms:setvalue ref="instance('instance')/YesNo" value="if ( instance('instance')/YesNo = 'Yes' ) then 'Yes' else 'No'" />
        </xforms:action>
      </xforms:select>
      <br/>
      <xforms:output ref="instance('instance')/YesNo">
        <xforms:label>Yes/No:</xforms:label>
      </xforms:output>
    </xhtml:body>
</xhtml:html>

此示例包含两种可能的解决方案:首先是绑定到布尔实例节点的标准布尔复选框,其操作为第二个节点设置是"/否"值.此解决方案运行良好,但需要第二个数据节点,由于架构的原因我无法创建(在上面的示例中,我通常可以创建第二个实例来存储此值,但在实际项目中,这些复选框位于重复块中,我必须创建额外的表这个值似乎非常复杂),其次是选择具有一个且唯一值是"的项目,以及在设置空值时尝试设置否"值的操作(未选择的项目).不幸的是,当这个项目被取消选择时,它无法再次选择(自动取消选择).你们有没有针对此类问题的解决方案?

This example contains two possible solutions: First is standard boolean checkbox bound to boolean instance node with an action that set 'Yes'/'No' value for the second node. This solution works well but requires second data node which I cannot create due to schema (in the example above I could generally create second instance to store this value but in real project these checkboxes are in repeat block and I would have to create extra table of values for this which seems to be to much complicated), Second is select item with one and only value 'Yes' and action that tries to set 'No' value when empty value is set (unselected item). Unfortunatelly when this item is deselected it's unable to select it again (deselects automatically). Has any of you solution for such an issue?

提前致谢

推荐答案

希望这能解决您的问题..

Hope this solves your problem..

<xhtml:html xmlns:xforms="http://www.w3.org/2002/xforms"
    xmlns:f="http://orbeon.org/oxf/xml/formatting"
    xmlns:xhtml="http://www.w3.org/1999/xhtml"
    xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
    xmlns:ev="http://www.w3.org/2001/xml-events"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    >

    <xhtml:head>
        <xforms:model xmlns:xforms="http://www.w3.org/2002/xforms"
                xmlns:xs="http://www.w3.org/2001/XMLSchema" id="main-model">
          <xforms:instance id="instance">
            <main>
              <Boolean value="true">Yes</Boolean>
            </main>
          </xforms:instance>
          <xforms:bind ref="Boolean/@value" type="xforms:boolean" readonly="false()" />
          <xforms:bind ref="Boolean" calculate="if(@value=true()) then 'Yes' else 'No'" readonly="false()" />
        </xforms:model>
    </xhtml:head>
    <xhtml:body>
      <xforms:input ref="instance('instance')/Boolean/@value">
        <xforms:label>Boolean: </xforms:label>
      </xforms:input>
      <br/>
      <xforms:output ref="instance('instance')/Boolean">
        <xforms:label>Boolean:</xforms:label>
      </xforms:output>
      <br/>
      <xforms:output ref="instance('instance')/Boolean/@value">
        <xforms:label>Boolean/@value:</xforms:label>
      </xforms:output>
      <br/>
      <br/>


    </xhtml:body>
</xhtml:html>

如果不允许您对 xml 节点使用属性,则在用户处理表单时使用布尔值.在提交事件时,您可以将布尔值设置为 Yes 或 No 并将数据推送到外部系统.

In case if you are not allowed to use attributes to your xml node, then have the boolean values while user working on the form. On submit event, you can set the boolean values to Yes or No and push the data to external system.

这篇关于如何创建带有“是"/“否"值而不是“真"/“假"值的复选框项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆