Skip to content

Instantly share code, notes, and snippets.

@ebruchez
Created July 6, 2012 16:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ebruchez/3061162 to your computer and use it in GitHub Desktop.
Save ebruchez/3061162 to your computer and use it in GitHub Desktop.
XForms: Clearing non-relevant elements upon submission
<xh:html
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xh="http://www.w3.org/1999/xhtml"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:exf="http://www.exforms.org/exf/1-0"
xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
xmlns:ev="http://www.w3.org/2001/xml-events">
<xh:head>
<xf:model id="model">
<xf:instance id="instance">
<instance relevant="true">
<a/>
<b/>
</instance>
</xf:instance>
<xf:bind ref="a" relevant="instance()/@relevant = 'true'"/>
<xf:bind ref="b" relevant="instance()/@relevant = 'false'"/>
<xf:submission id="save" relevant="false" ref="instance()" action="echo:" method="post" replace="instance">
<xf:setvalue ev:event="xforms-submit" xxf:iterate="//*[not(exf:relevant(.))]" ref="."/>
</xf:submission>
</xf:model>
</xh:head>
<xh:body>
<xf:input ref="a"/>
<xf:input ref="b"/>
<xf:trigger>
<xf:label>Toggle</xf:label>
<xf:setvalue ev:event="DOMActivate" ref="@relevant" value="if (. = 'true') then 'false' else 'true'"/>
</xf:trigger>
<xf:submit submission="save">
<xf:label>Save</xf:label>
</xf:submit>
<fr:xforms-inspector xmlns:fr="http://orbeon.org/oxf/xml/form-runner"/>
</xh:body>
</xh:html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment