adding bindings in the model with XForms actions?

Hi,

I have been confronted with the need to build a form where the user is
able to insert new nodes in the instance data (and, consequently, new
input controls (repeat items) in the UI). At the same time, it happens
that the model of my XForms document contains bindings that concern the
same collection of instance data nodes as the one used for the repeat.
Consider the following example:

<xforms>
   <head>
      <model>
         <instance>

   <my:photoalbum>
           <my:images>
            <my:image src="a"/>
            <my:image src="b"/>
            <my:image src="c"/>
          </my:images>

          .....

          <my:thumbnails>
          <my:thumbnail src="a">
           <my:thumbnail src="b">
           <my:thumbnail src="c">
          </my:thumbnails>
         </my:photoalbum>

        </instance>
        <bind nodeset="thumbnail[1]/@src" calculate="image[1]/@src"/>
        <bind nodeset="thumbnail[2]/@src" calculate="image[2]/@src"/>
        <bind nodeset="thumbnail[3]/@src" calculate="image[3]/@src"/>
      </model>
   </head>
   <body>
      <group>
        <repeat nodeset="image" >
    <upload ref="@src" mediatype="image/*"/>
  </repeat>
  <trigger>
    <insert nodeset="image" at="index(last())" position="after"/>
    <insert nodeset="thumbnail" at="index(last())"
position="after"/>
        </trigger>
      </group>
   </body>
</xforms>

There is one explicit binding for each (image, thumbnail) pair in the
instance data. With the repeat / trigger mechanism I am able to insert
new (image, thumbnail) pairs, but how do I enforce that the value of the
src attribute of my newly inserted thumbnail will always be synchronized
the value of the src attribute of my newly inserted image? In the UI
there will only be one new control bound to the src of the new image.

One solution would be to have an XForms action that does just that, so
the trigger becomes:

   <trigger>
    <insert nodeset="image" at="index(last())" position="after"/>
    <insert nodeset="thumbnail" at="index(last())"
position="after"/>
    <!-- is there a way to do this, currently? -->
    <setbind nodeset="thumbnails[last()]/@src"
calculate="image[last()]/@src"/>
        </trigger>

So do you think there is a way to solve this problem with the existing
XForms mechanisms and, if not, do you think that a "setbind" action
makes sense?

Thanks,
Andrei

Received on Monday, 20 December 2004 14:07:44 UTC