Skip to content

Instantly share code, notes, and snippets.

@avernet
Created September 26, 2011 22:28
Show Gist options
  • Save avernet/1243590 to your computer and use it in GitHub Desktop.
Save avernet/1243590 to your computer and use it in GitHub Desktop.
Updating another data structure when a value changes
<!--
More on this at:
http://stackoverflow.com/questions/7560527/orbeon-xforms-box-select-handle-selection-deselection-example
Copyright (C) 2011 Orbeon, Inc.
This program is free software; you can redistribute it and/or modify it under the terms of the
GNU Lesser General Public License as published by the Free Software Foundation; either version
2.1 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
The full text of the license is available at http://www.gnu.org/copyleft/lesser.html
-->
<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fr="http://orbeon.org/oxf/xml/form-runner">
<xhtml:head>
<xhtml:title>XForms Hello</xhtml:title>
<xforms:model>
<xforms:instance>
<box-results/>
</xforms:instance>
<xforms:instance id="codes">
<box-select>
<item selected="false">
<label>Cat</label>
<value>cat</value>
</item>
<item selected="false">
<label>Dog</label>
<value>dog</value>
</item>
<item selected="false">
<label>Bird</label>
<value>bird</value>
</item>
<item selected="false">
<label>Fish</label>
<value>fish</value>
</item>
</box-select>
</xforms:instance>
</xforms:model>
</xhtml:head>
<xhtml:body>
<fr:box-select ref="." id="box-select-control">
<xforms:action ev:event="xforms-value-changed">
<xxforms:variable name="selected-values" select="tokenize(., '\s+')"/>
<xforms:setvalue xxforms:iterate="instance('codes')/item" ref="@selected">false</xforms:setvalue>
<xforms:setvalue xxforms:iterate="$selected-values"
ref="for $v in . return instance('codes')/item
[value = $v]/@selected">true</xforms:setvalue>
</xforms:action>
<xforms:itemset nodeset="instance('codes')/item">
<xforms:label ref="label"/>
<xforms:value ref="value"/>
</xforms:itemset>
</fr:box-select>
</xhtml:body>
</xhtml:html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment