Skip to content

Instantly share code, notes, and snippets.

@orbeon
Created June 15, 2010 02: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 orbeon/438616 to your computer and use it in GitHub Desktop.
Save orbeon/438616 to your computer and use it in GitHub Desktop.
Super simple example of a dynamic dropdown with values ranging from 1 to a configurable maximum
<xh:html xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xh="http://www.w3.org/1999/xhtml"
xmlns:ev="http://www.w3.org/2001/xml-events">
<xh:head>
<xf:model>
<xf:instance id="instance">
<form>
<value>1</value>
<max>9</max>
</form>
</xf:instance>
</xf:model>
</xh:head>
<xh:body>
<xf:select1 ref="value">
<xf:itemset ref="1 to ../max">
<xf:label value="."/>
<xf:value value="."/>
</xf:itemset>
</xf:select1>
<xf:trigger>
<xf:label>Increase</xf:label>
<xf:setvalue ev:event="DOMActivate" ref="max" value=". + 1"/>
</xf:trigger>
<xf:trigger>
<xf:label>Decrease</xf:label>
<xf:setvalue ev:event="DOMActivate" ref="max" value=". - 1"/>
</xf:trigger>
</xh:body>
</xh:html>
@orbeon
Copy link
Author

orbeon commented Jun 15, 2010

This is a super simple example of a dynamic dropdown with values ranging from 1 to a configurable maximum.

There are two interesting bits in that line:

<xf:itemset ref="1 to ../max">

First, we use @ref instead of @nodeset. The XForms Working Group recently proposed to deprecate @nodeset (for several reasons) and now recommends experimenting with using @ref instead. But you could use @nodeset as well and it wouldn't make a difference.

Second is the XPath expression. This is an XPath 2.0 expression expressing a range of number values from 1 to whatever the value of ../max is.

Supporting atomic values (as in the number "1") in xf:itemset is an Orbeon Forms extension. It makes sense for XPath 2.0-aware implementations to support this though, and we hope that along with XPath 2.0 support in XForms 1.2, this will be standardized as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment