我是 XHTML、XForm 和 Orbeon 的新手,我有一个关于在 Orbeon Forms 中使用客户端 javascript 检索 HTML 元素 ID 的问题。在普通 HTML 中,我只使用了 getElementById 函数,Orbeon 的文档建议使用 function用于检索元素的值(术语为 Controller )。
ORBEON.xforms.Document.getValue(controlIdOrElement)
但是,使用 Orbeon From(片段),例如
<xf:bind id="fr-form-binds" ref="instance('fr-form-instance')">
<xf:bind id="section-1-bind" name="section-1" ref="section-1">
<xf:bind id="cvr-input-bind" name="cvr-input" ref="cvr-input"/>
(...)
<fr:section id="section-1-control" bind="section-1-bind">
<xf:label ref="$form-resources/section-1/label"/>
<fr:grid>
<xh:tr>
<xh:td>
<xf:input id="cvr-input-control" bind="cvr-input-bind">
<xf:label ref="$form-resources/cvr-input/label"/>
<xf:hint ref="$form-resources/cvr-input/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
</xf:input>
</xh:td>
(...)
getValue 函数未找到任何参数变体的值
- cvr 输入
- cvr-输入控制
- cvr-输入绑定(bind)
以字符串形式给出。
当我检查生成的表单时,我看到输入元素已获得 id section-1-control ≡xf-383 ≡cvr-input-control ,这是有道理的 getValue 不能在上面的三个变体中找到它。
我制作了一个触发按钮(如下所示),它会产生预期的结果(将输入值映射到另一个 Controller /元素),但我无法想象该解决方案必须涉及对该部分进行硬编码- 元素 ID 的部分。
因此我的问题是:当编码 ID 在最终 View 中修改时,如何检索元素/ Controller (或其值)?
<xf:trigger id="get-pnumbers-btn-control" bind="get-pnumbers-btn-bind">
<xf:label ref="$form-resources/get-pnumbers-btn/label"/>
<xf:hint ref="$form-resources/get-pnumbers-btn/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
<xxf:script ev:event="DOMActivate" type="javascript">
var cvrInputElementId = "section-1-control≡xf-383≡cvr-input-control";
var cvrOutputElementId = "section-1-control≡xf-383≡cvr-output-control";
var cvrInput = ORBEON.xforms.Document.getValue(cvrInputElementId);
ORBEON.xforms.Document.setValue(cvrOutputElementId, cvrInput);
</xxf:script>
</xf:trigger>
最佳答案
xxf:client-id()
function解析 id 并返回客户端 id。这可能会有帮助。然后,您需要以某种方式将该 id 传递给脚本(即将推出的 4.11 中为 easy,但之前有点困难)。
您还可以使用 jQuery,查找 id
以某个字符串结尾的元素:
var clientId = ORBEON.jQuery('[id $= "cvr-input-control"]').attr('id')
有一封 RFE 发送至 improve the id scheme .
关于javascript - 如何在 Orbeon Forms 的客户端 javascript 中获取元素 id?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35453059/