Orbeon JavaScript API - 从 fr:section 中访问控制值? [英] Orbeon JavaScript API - Access to control value from within fr:section?

查看:41
本文介绍了Orbeon JavaScript API - 从 fr:section 中访问控制值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎存在与 fr:section 中嵌入的 xf:triggers 相关的问题,请参阅以下两个示例表单.

There seems to be a problem related to xf:triggers embedded in a fr:section, see the following two sample forms.

对此有任何已知的解决方法吗?

Any known workarounds for this?

<xh:html xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:exf="http://www.exforms.org/exf/1-0" xmlns:fb="http://orbeon.org/oxf/xml/form-builder" xmlns:fr="http://orbeon.org/oxf/xml/form-runner" xmlns:saxon="http://saxon.sf.net/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sql="http://orbeon.org/oxf/xml/sql" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xh="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xxf="http://orbeon.org/oxf/xml/xforms" xmlns:xxi="http://orbeon.org/oxf/xml/xinclude">
    <xh:head>
        <xh:title>Test 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">
                <form>
                    <message-section>
                        <message>my message</message>
                    </message-section>
                </form>
            </xf:instance>
            <!-- Metadata -->
            <xf:instance id="fr-form-metadata" xxf:exclude-result-prefixes="#all" xxf:readonly="true">
                <metadata>
                    <application-name>test-app</application-name>
                    <form-name>client-js-sample</form-name>
                    <title xml:lang="en">Test Form</title>
                    <description xml:lang="en"/>
                    <singleton>false</singleton>
                </metadata>
            </xf:instance>
        </xf:model>
    </xh:head>
    <xh:body>
        <fr:view>
            <fr:body xmlns:oxf="http://www.orbeon.com/oxf/processors" xmlns:p="http://www.orbeon.com/oxf/pipeline" xmlns:xbl="http://www.w3.org/ns/xbl">
                <xf:output id="message" ref="message-section/message"/>
                <xf:trigger>
                    <xf:label>Show</xf:label>
                    <xxf:script ev:event="DOMActivate" type="javascript">
                        var message = ORBEON.xforms.Document.getValue("message");
                        window.alert("message:" + message);
                    </xxf:script>
                </xf:trigger>
            </fr:body>
        </fr:view>
    </xh:body>
</xh:html>

嵌入在 fr:section 中的触发器 - 不起作用

一旦 xf:trigger 被嵌入到 fr:section 中,Orbeon JavaScript API 就不再找到控制 message.这是相同的基本形式,除了额外的 fr:section.

trigger embedded in fr:section - doesn't work

As soon as xf:trigger is embedded in an fr:section, the Orbeon JavaScript API doesn't find the control message anymore. Here's the same rudimentary form, except for an additional fr:section.

<xh:html xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:exf="http://www.exforms.org/exf/1-0" xmlns:fb="http://orbeon.org/oxf/xml/form-builder" xmlns:fr="http://orbeon.org/oxf/xml/form-runner" xmlns:saxon="http://saxon.sf.net/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sql="http://orbeon.org/oxf/xml/sql" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xh="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xxf="http://orbeon.org/oxf/xml/xforms" xmlns:xxi="http://orbeon.org/oxf/xml/xinclude">
    <xh:head>
        <xh:title>Test 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">
                <form>
                    <message-section>
                        <message>my message</message>
                    </message-section>
                </form>
            </xf:instance>
            <!-- Metadata -->
            <xf:instance id="fr-form-metadata" xxf:exclude-result-prefixes="#all" xxf:readonly="true">
                <metadata>
                    <application-name>test-app</application-name>
                    <form-name>client-js-sample</form-name>
                    <title xml:lang="en">Test Form</title>
                    <description xml:lang="en"/>
                    <singleton>false</singleton>
                </metadata>
            </xf:instance>
        </xf:model>
    </xh:head>
    <xh:body>
        <fr:view>
            <fr:body xmlns:oxf="http://www.orbeon.com/oxf/processors" xmlns:p="http://www.orbeon.com/oxf/pipeline" xmlns:xbl="http://www.w3.org/ns/xbl">
                <fr:section>
                    <xf:label>Test Section</xf:label>
                    <xf:output id="message" ref="message-section/message"/>
                    <xf:trigger>
                        <xf:label>Show</xf:label>
                        <xxf:script ev:event="DOMActivate" type="javascript">
                       var message = ORBEON.xforms.Document.getValue("message");
                        window.alert("message:" + message);
                    </xxf:script>
                    </xf:trigger>
                </fr:section>
            </fr:body>
        </fr:view>
    </xh:body>
</xh:html>

推荐答案

出现这种情况是因为section是XBL控件,当你的控件在XBL控件内部时,在生成的HTML中,添加了容器的id作为控件 ID 的前缀.所以你可以使用:

This is happening because the section is an XBL control, and when your control is inside an XBL control, in the generated HTML, the id of the container is added as a prefix to the id of your control. So you can use:

var messageControl = ORBEON.jQuery('*[id $= "message"]')[0];
alert(ORBEON.xforms.Document.getValue(messageControl));

有关这方面的更多信息,请参阅文档中关于 如何在使用 Form Builder 创建的表单上使用 getValue()setValue().

For more on this, see the section of the documentation on how to use getValue() and setValue() on forms created with Form Builder.

这篇关于Orbeon JavaScript API - 从 fr:section 中访问控制值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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