ORBEON.xforms.Document.setValue getValue dispatchEvent 怎么用?
ORBEON.xforms.Document.setValue getValue dispatchEvent how to use?
我已经在 Orbeon 4.6 和 4.7 上试过了。
ORBEON.xforms.Document.setValue、getValue 或 DispatchEvents 命令在调用时抛出错误对话框。
如果有人有幸让这些工作发挥作用,我们将不胜感激。
请查看下面的 xhtml 片段,当我 运行 警告消息显示 "undefined" 而它应该显示“42”时,如果我将 getValue() 更改为 setValue( ) 并将名称和值作为参数传递给系统 returns 错误 :
<xf:instance id="fr-form-instance" xxf:exclude-result-prefixes="#all">
<form>
<section-1>
<control-1/>
<foo>42</foo>
<bar/>
</section-1>
</form>
</xf:instance>
.......
<xh:td>
<xf:input id="control-1-control" bind="control-1-bind">
<xf:label ref="$form-resources/control-1/label"/>
<xf:hint ref="$form-resources/control-1/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
</xf:input>
<xf:input ref="foo" id="foo">
<xf:label class="fixed-width">Value of foo:</xf:label>
</xf:input>
<xf:output ref="bar">
<xf:label class="fixed-width">Value of bar:</xf:label>
</xf:output>
<xf:trigger>
<xf:label>JavaScript</xf:label>
<xxf:script ev:event="DOMActivate">
alert(ORBEON.xforms.Document.getValue("foo"));
</xxf:script>
</xf:trigger>
</xh:td>
它不起作用,因为您需要使用 HTML 中的 ID,而 HTML 中的 ID 在两个方面与控件名称不同:
- Form Builder 在名称末尾添加
-control
以生成 ID。
- 因为对于 Form Runner,控件位于 XBL 组件内部,这些组件的 ID 以控件的 ID 为前缀。
因此,如果您的控件在 Form Builder 中被命名为 my-control
,我建议您使用以下方法在 JavaScript 中获取它的值:
var control = ORBEON.jQuery('*[id $= "my-control-control"]');
var value = ORBEON.xforms.Document.getValue(control.attr('id'));
我已经在 Orbeon 4.6 和 4.7 上试过了。
ORBEON.xforms.Document.setValue、getValue 或 DispatchEvents 命令在调用时抛出错误对话框。
如果有人有幸让这些工作发挥作用,我们将不胜感激。
请查看下面的 xhtml 片段,当我 运行 警告消息显示 "undefined" 而它应该显示“42”时,如果我将 getValue() 更改为 setValue( ) 并将名称和值作为参数传递给系统 returns 错误 :
<xf:instance id="fr-form-instance" xxf:exclude-result-prefixes="#all">
<form>
<section-1>
<control-1/>
<foo>42</foo>
<bar/>
</section-1>
</form>
</xf:instance>
.......
<xh:td>
<xf:input id="control-1-control" bind="control-1-bind">
<xf:label ref="$form-resources/control-1/label"/>
<xf:hint ref="$form-resources/control-1/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
</xf:input>
<xf:input ref="foo" id="foo">
<xf:label class="fixed-width">Value of foo:</xf:label>
</xf:input>
<xf:output ref="bar">
<xf:label class="fixed-width">Value of bar:</xf:label>
</xf:output>
<xf:trigger>
<xf:label>JavaScript</xf:label>
<xxf:script ev:event="DOMActivate">
alert(ORBEON.xforms.Document.getValue("foo"));
</xxf:script>
</xf:trigger>
</xh:td>
它不起作用,因为您需要使用 HTML 中的 ID,而 HTML 中的 ID 在两个方面与控件名称不同:
- Form Builder 在名称末尾添加
-control
以生成 ID。 - 因为对于 Form Runner,控件位于 XBL 组件内部,这些组件的 ID 以控件的 ID 为前缀。
因此,如果您的控件在 Form Builder 中被命名为 my-control
,我建议您使用以下方法在 JavaScript 中获取它的值:
var control = ORBEON.jQuery('*[id $= "my-control-control"]');
var value = ORBEON.xforms.Document.getValue(control.attr('id'));