orbeon - 基于 Orbeon 中重复部分的迭代控件动态值的条件
问题描述
我在重复部分有一个复选框。在迭代中只能勾选一次。一旦在重复部分中打勾,其余部分必须是只读的。例如:“一旦让他成为主要申请人”被选中,那么其他(上一个和下一个)迭代中的复选框必须被禁用或隐藏或只读,值为空。请帮助我如何实现这一目标。
<xh:html xmlns:xh="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xxi="http://orbeon.org/oxf/xml/xinclude"
xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
xmlns:exf="http://www.exforms.org/exf/1-0"
xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
xmlns:saxon="http://saxon.sf.net/"
xmlns:sql="http://orbeon.org/oxf/xml/sql"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:fb="http://orbeon.org/oxf/xml/form-builder">
<xh:head>
<xh:title>Untitled Form</xh:title>
<xf:model id="fr-form-model" xxf:expose-xpath-types="true">
<!-- Main instance -->
<xf:instance id="fr-form-instance" xxf:exclude-result-prefixes="#all" xxf:index="id">
<form>
<section-1>
<section-1-iteration>
<surname/>
<checkbox>false</checkbox>
</section-1-iteration>
</section-1>
</form>
</xf:instance>
<!-- Bindings -->
<xf:bind id="fr-form-binds" ref="instance('fr-form-instance')">
<xf:bind id="section-1-bind" ref="section-1" name="section-1">
<xf:bind id="section-1-iteration-bind" ref="section-1-iteration"
name="section-1-iteration">
<xf:bind id="surname-bind" ref="surname" name="surname" xxf:whitespace="trim"/>
<xf:bind id="checkbox-bind" ref="checkbox" name="checkbox" type="xf:boolean"
readonly="(../checkbox)"/>
</xf:bind>
</xf:bind>
</xf:bind>
<!-- Metadata -->
<xf:instance xxf:readonly="true" id="fr-form-metadata" xxf:exclude-result-prefixes="#all">
<metadata>
<application-name>a</application-name>
<form-name>a</form-name>
<title xml:lang="en">Untitled Form</title>
<description xml:lang="en"/>
<singleton>false</singleton>
</metadata>
</xf:instance>
<!-- Attachments -->
<xf:instance id="fr-form-attachments" xxf:exclude-result-prefixes="#all">
<attachments>
<css mediatype="text/css" filename="" size=""/>
<pdf mediatype="application/pdf" filename="" size=""/>
</attachments>
</xf:instance>
<!-- All form resources -->
<!-- Don't make readonly by default in case a service modifies the resources -->
<xf:instance id="fr-form-resources" xxf:readonly="false" xxf:exclude-result-prefixes="#all">
<resources>
<resource xml:lang="en">
<surname>
<label>Full Name</label>
<hint/>
</surname>
<checkbox>
<label>Make him primary applicant</label>
<hint/>
</checkbox>
<section-1>
<label>Caregiver</label>
</section-1>
</resource>
</resources>
</xf:instance>
<xf:instance xxf:readonly="true" id="section-1-template" xxf:exclude-result-prefixes="#all">
<section-1-iteration>
<surname/>
<checkbox>false</checkbox>
</section-1-iteration>
</xf:instance>
</xf:model>
</xh:head>
<xh:body>
<fr:view>
<fr:body xmlns:xbl="http://www.w3.org/ns/xbl" xmlns:p="http://www.orbeon.com/oxf/pipeline"
xmlns:oxf="http://www.orbeon.com/oxf/processors">
<fr:section id="section-1-section" bind="section-1-bind" repeat="content" min="1"
template="instance('section-1-template')"
apply-defaults="true"
fb:initial-iterations="first">
<xf:label ref="$form-resources/section-1/label"/>
<fr:grid id="grid-2-grid">
<fr:c x="1" y="1" w="12">
<xf:input id="surname-control" bind="surname-bind">
<xf:label ref="$form-resources/surname/label"/>
<xf:hint ref="$form-resources/surname/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
</xf:input>
</fr:c>
<fr:c x="1" y="2" w="12">
<fr:checkbox-input xmlns="http://orbeon.org/oxf/xml/form-builder"
xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"
id="checkbox-control"
bind="checkbox-bind">
<xf:label ref="$form-resources/checkbox/label"/>
<xf:hint ref="$form-resources/checkbox/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
</fr:checkbox-input>
</fr:c>
</fr:grid>
</fr:section>
</fr:body>
</fr:view>
</xh:body>
解决方案
Assuming you named your Single Checkbox field my-checkbox
, then you can use the following validation XPath expression:
count(//my-checkbox[string() = 'true']) <= 1 or
string() != 'true'
With this expression, if you have more than one checkbox checked, then all the checked checkboxes will be marked as invalid, thus informing users they must change their selection, and preventing the data from being saved or submitted (if you indeed don't want invalid data to be saved or submitted).
You might also want to add a custom alert message, like "you can't select more than one primary applicant", so users know what the problem is.
推荐阅读
- java - 我的程序没有与 Executor 返回/结束
- python - 管理和终止任何进程的强大方法
- firebase - firebase:admin.auth().updateUser() 导致 auth/user-token-expired
- c++ - 用 c++17 算法并行化一个简单的循环
- javascript - JavaScript设置元素属性数据返回json数据为空
- java - 如何清除未使用的滑行缓存?
- apache-spark - 在哪种情况下,来自驱动程序节点的对象被序列化并发送到 apache spark 中的工作节点
- python-3.x - 随机挑选并更改类实例的变量
- r - 在 R Boxplot (ggpubr) 中调整字体大小和小数位
- javascript - 仅在 Firefox 上:finally 不是函数 | 被包覆盖的承诺