问题
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?
trigger not embedded in fr:section - works fine
<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>
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>
回答1:
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));
For more on this, see the section of the documentation on how to use getValue() and setValue() on forms created with Form Builder.
来源:https://stackoverflow.com/questions/35741178/orbeon-javascript-api-access-to-control-value-from-within-frsection