W3C home > Mailing lists > Public > public-forms@w3.org > January 2012

ACTION-1854 Nick van den Bleeken to describe initialization value use cases and ask Erik Bruchez to do the same

From: Erik Bruchez <ebruchez@orbeon.com>
Date: Wed, 11 Jan 2012 11:36:35 -0800
Message-ID: <CAAc0PEVW=fVZFySC6JyKEjs7bj8qj7AEtf8rDDRTm+vg7+p7-Q@mail.gmail.com>
To: public-forms@w3.org
All,

I just read today's minutes on this [1].

Our implementation has an extension MIP called @xxforms:default. [2]

The behavior of this MIP is to set an initial value into a node. It
does *not* create new nodes if they are missing.

Its behavior is exactly the same as @calculate, except that it runs
only once during the first xforms-recalculate that occurs
(xforms:reset might reset that "first" flag as well, but we don't
implement this).

Note that @xxforms:default does not really act as a default value in
the sense of setting a value if the value is missing (blank). Instead
it sets an *initial* default value only. We have been pondering
renaming it to @xxforms:initial (or something else) instead.

In addition, we have an extension attribute, @xxforms:defaults, on the
xforms:recalculate action, which allows running forcing the evaluation
of the @xxforms:default expressions, which otherwise will not run upon
subsequent xforms-recalculate.

The implementation of @xxforms:default and @xxforms:defaults is very
simple as it's very similar to what happens with @calculate.

As far as use cases, a simple one is setting an initial date:

  <xforms:bind ref="start-date" xxforms:default="current-date()"/>

When the user opens the form, start-date contains today's date. The
user can then change that default. (This is why the MIP is called
"default".)

You would think that an alternative would be to write:

  <xforms:bind ref="start-date" calculate="if (normalize-space() = '')
then current-date() else ."/>

But then the behavior would be different: if the user clears the date,
the calculate will immediately replace the blank value with today's
date, which is usually not what you want.

-Erik

[1] http://lists.w3.org/Archives/Public/public-forms/2012Jan/att-0004/2012-01-04.html#topic9
[2] http://wiki.orbeon.com/forms/doc/developer-guide/xforms-mips#TOC-The-xxforms:default-MIP
Received on Wednesday, 11 January 2012 21:32:19 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 1 October 2013 22:06:56 UTC