Skip to content

Instantly share code, notes, and snippets.

@ebruchez
Created June 10, 2016 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ebruchez/6b4bb955f3ce4316a274c9bc78ff6c1c to your computer and use it in GitHub Desktop.
Save ebruchez/6b4bb955f3ce4316a274c9bc78ff6c1c to your computer and use it in GitHub Desktop.
Insert into other grid
<xh:html xmlns:xh="http://www.w3.org/1999/xhtml"
xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
xmlns:xxi="http://orbeon.org/oxf/xml/xinclude"
xmlns:saxon="http://saxon.sf.net/"
xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sql="http://orbeon.org/oxf/xml/sql"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:exf="http://www.exforms.org/exf/1-0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fb="http://orbeon.org/oxf/xml/form-builder"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<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>
<section1>
<grid1>
<grid1-iteration>
<name/>
</grid1-iteration>
</grid1>
</section1>
<section2>
<grid2>
</grid2>
</section2>
</form>
</xf:instance>
<!-- Bindings -->
<xf:bind id="fr-form-binds" ref="instance('fr-form-instance')">
<xf:bind id="section1-bind" name="section1" ref="section1">
<xf:bind id="grid1-bind" ref="grid1" name="grid1">
<xf:bind id="grid1-iteration-bind" ref="grid1-iteration" name="grid1-iteration">
<xf:bind id="name-bind" ref="name" name="name" xxf:whitespace="trim"/>
</xf:bind>
</xf:bind>
</xf:bind>
<xf:bind id="section2-bind" ref="section2" name="section2">
<xf:bind id="grid2-bind" ref="grid2" name="grid2">
<xf:bind id="grid2-iteration-bind" ref="grid2-iteration" name="grid2-iteration">
<xf:bind id="name-copy-bind" ref="name-copy" name="name-copy"/>
</xf:bind>
</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 -->
<xf:instance xxf:readonly="true" id="fr-form-resources" xxf:exclude-result-prefixes="#all">
<resources>
<resource xml:lang="en">
<name-copy>
<label>Name from Section 1</label>
<hint/>
</name-copy>
<name>
<label>Name</label>
<hint/>
</name>
<section1>
<label>Section 1</label>
</section1>
<section2>
<label>Section 2</label>
<help/>
</section2>
</resource>
</resources>
</xf:instance>
<!-- Utility instances for services -->
<xf:instance id="fr-service-request-instance" xxf:exclude-result-prefixes="#all">
<request/>
</xf:instance>
<xf:instance id="fr-service-response-instance" xxf:exclude-result-prefixes="#all">
<response/>
</xf:instance>
<xf:instance xxf:readonly="true" xxf:exclude-result-prefixes="#all" id="grid1-template">
<grid1-iteration>
<name/>
</grid1-iteration>
</xf:instance>
<xf:instance xxf:readonly="true" xxf:exclude-result-prefixes="#all" id="grid2-template">
<grid2-iteration>
<name-copy/>
</grid2-iteration>
</xf:instance>
<xf:action event="fr-iteration-added" observer="grid1-control">
<xf:var name="source-names" value="xxf:bind('grid1-bind')//name/string()"/>
<xf:var name="dest-names" value="xxf:bind('grid2-bind')//name-copy/string()"/>
<xf:var name="new-names" value="$source-names[normalize-space(.) != '' and not(. = $dest-names)]"/>
<xf:action iterate="$new-names">
<xf:var name="new-name" value="."/>
<xf:insert
context="xxf:bind('grid2-bind')"
ref="*"
origin="instance('grid2-template')"/>
<xf:setvalue
ref="xxf:bind('grid2-bind')/*[last()]//name-copy"
value="$new-name"/>
</xf:action>
</xf:action>
<xf:action event="fr-iteration-removed" observer="grid1-control">
</xf:action>
</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="section1-control" bind="section1-bind">
<xf:label ref="$form-resources/section1/label"/>
<fr:grid id="grid1-control" bind="grid1-bind" repeat="content" min="1"
template="instance('grid1-template')"
apply-defaults="true"
fb:initial-iterations="first">
<xh:tr>
<xh:td>
<xf:input id="name-control" bind="name-bind">
<xf:label ref="$form-resources/name/label"/>
<xf:hint ref="$form-resources/name/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
</xf:input>
</xh:td>
<xh:td/>
</xh:tr>
</fr:grid>
</fr:section>
<fr:section id="section2-control" bind="section2-bind">
<xf:label ref="$form-resources/section2/label"/>
<fr:grid id="grid2-control" bind="grid2-bind" repeat="content"
template="instance('grid2-template')"
apply-defaults="true"
fb:initial-iterations="first">
<xh:tr>
<xh:td>
<xf:output id="name-copy-control" bind="name-copy-bind">
<xf:label ref="$form-resources/name-copy/label"/>
<xf:hint ref="$form-resources/name-copy/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
</xf:output>
</xh:td>
<xh:td/>
<xh:td/>
</xh:tr>
</fr:grid>
</fr:section>
</fr:body>
</fr:view>
</xh:body>
</xh:html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment