How to use the 'if' attribute in xforms with html elements?

1k Views Asked by At

I have a <div> element which I want to use based on the xforms instance value.

Something like:

    <xf:trigger appearance="minimal"  >
                <xf:label >
                  ..
                 <div  if="instance('scope')= 'user'">   <!-- I know this doesn't work -->
                 </div>
                  ..
                </xf:label>
                    ....      
     </xf:trigger>   

Is this 'if' attribute where we check instance values only available with the <xf:action>,<xf:submission> etc. elements and not with regular html elements ? Or is there a way I am missing ?

2

There are 2 best solutions below

1
On BEST ANSWER

For conditional HTML elements, XForms allows to define an xf:group element with a ref attribute.

The trick to emulate an "if" is to use a predicate as in ".[instance('scope') = 'user']": this way, the context node remains the same but the xf:group content will be disabled if the condition in the predicate is false.

0
On

The 'if' attribute is only valid on XForms action elements (XForms 1.1). However as Alain pointed out you can use a 'ref' attribute (which is defined for all XForms controls) and use relevance to achieve what you want (conditional display of elements). The binding expression must evaluate to boolean 'true' or 'false' which in turn makes controls visible or invisible (relevant).

Also the trigger elements can be bound with a 'ref'. So for your example you could have:

<xf:trigger ref="someXPath[. eq 'fooValue']">...</xf:trigger>
...
<xf:trigger ref="someXPath[. eq 'barValue']">...</xf:trigger>

A value of 'fooValue' would then display the first trigger. A value of 'barValue' would display the second trigger.

A bit more verbose than your pseudo-code but working.