Re: Question about form design with optional elements

Hi,

this is only part of the trick, because when the relevant MIP is false, 
"associated form controls (and any children) and group and switch 
elements (including content) must be made unavailable, removed from the 
navigation order, and not allowed focus. Typically, non-relevant content 
is not presented, or it may be styled as disabled." [1]

Setting all empty fields to non-relevant would make them unavailable for 
editing. However, if you use a controller instance keeping the editing 
state, you can use this trick:

<xf:instance id="controller" xmlns="">
     <controller>
         <state>edit</state>
     </controller>
</xf:instance>

Then you can use binding expression like:

<xf:bind nodeset="instance('maximal-base')/*" 
relevant="instance('controller')/state='submit' .!=''"/>

So all fields are relevant when the state is not 'submit'. Last part of 
the trick is using event handlers for the xforms-submit* events to set 
the state:

<xf:submission ...>
     <xf:setvalue ref="instance('controller')/state" 
ev:event="xforms-submit">submit</xf:setvalue>
     <xf:setvalue ref="instance('controller')/state" 
ev:event="xforms-submit-done">edit</xf:setvalue>
     <xf:setvalue ref="instance('controller')/state" 
ev:event="xforms-submit-error">edit</xf:setvalue>
     ...
</xf:submission>

Regards,
Uli.

[1] http://www.w3.org/TR/xforms/#model-prop-relevant

Swithun Crowe wrote:
> Hello
> 
> CJ Another approach is to start with a maximal base instance,
> CJ 
> CJ   <xf:instance id="maximal-base">
> CJ     <X>
> CJ       <a/>
> CJ       <b/>
> CJ       <c/>
> CJ     </X>
> CJ   </xf:instance>
> CJ 
> CJ and then remove any of the optional elements that are "empty" when the 
> CJ instance is submitted.  This approach requires expanding the starting 
> CJ state of the instance data to its maximal form before editing, and then 
> CJ pruning it back again after editing.  Our experiments have performed 
> CJ both expanding and pruning on the server side, although it may be 
> CJ possible to do these operations using XForms itself.  For example, 
> CJ pruning could be implemented using some creative "relevance" MIPs.  
> 
> This is what relevance is for. It needn't be very creative. Something 
> like:
> 
> <xf:bind nodeset="instance('maximal-base')/*" relevant=".!=''"/>
> 
> would do it. You might need to use CSS to ensure that elements are still 
> visible and editable while they are empty. But relevance will remove the 
> empties before the instance is submitted.
> 
> Swithun.
> 

-- 
Ulrich Nicolas Lissé

Received on Thursday, 17 July 2008 08:41:44 UTC