Reset fields to default on button press

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Reset fields to default on button press

fritz
Hi all,

I've this snippet  wich clears a portion of fields in a section.
                                   
<xf:action ev:event="DOMActivate" ev:observer="control-3-control">
      <xf:setvalue xxf:iterate="instance('fr-form-instance')/Fields/*"  value="''"/>
</xf:action> 

I'm trying to set them to default value but I'm not able to get it working.
with xxf:evaluate-bind-property(xxf:bind('Fields-bind')/*, 'xxf:default')  I got error  because too many args are passed,
but works if I point directly to child bind.

Is there a solution to what I want achieve??

Fritz
Reply | Threaded
Open this post in threaded view
|

Re: Reset fields to default on button press

Alessandro  Vernet
Administrator
Hi Fritz,

The first argument to xxf:evaluate-bind-property() must be the bind id, while in your call you're passing a set of nodes. You can set the value of all the fields in the `fields` section to their initial value with the following:

<xf:action ev:event="DOMActivate" ev:observer="reset-control">
    <xf:action iterate="instance('fr-form-instance')/fields/*">
        <xf:setvalue ref="."
                     value="xxf:evaluate-bind-property(concat(local-name(), '-bind'), 'xxf:default')"/>
    </xf:action>
</xf:action>

http://wiki.orbeon.com/forms/doc/developer-guide/xforms-xpath-functions#TOC-xxf:evaluate-bind-property-

And here is the source of the full form you can paste in Form Builder if you want to try this out.

https://gist.github.com/avernet/14b1729bed096da4516f

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: Reset fields to default on button press

fritz
Alex, Thank you very much for pointing me in right direction