Problem with action on event:xforms-change

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

Problem with action on event:xforms-change

pumbosha
Hallo,

I have a problem with xf:action. I make my own control, and I have an instance:

<xf:model>
    <xf:instance id="src"><value/></xf:instance>
</xf:model>

This instance is created to hold name of control from main instance, which is observer of my action:

<xf:action ev:event="xforms-value-changed" ev:observer="xxf:instance('fr-form-instance')/*/*[name() = saxon:evaluate(instance('src'))]">
    <xf:send ev:event="DOMActivate" submission=".." />
</xf:action>

Unfortunately it doesn't work. There is no effect after change input which is associated with instance('src'). What I'm doing wrong?

regards, Tom



Reply | Threaded
Open this post in threaded view
|

Re: Problem with action on event:xforms-change

Erik Bruchez
Administrator
Event observers are static, not dynamic, so you cannot use an XPath expressions as an observer.

What you can do is observe *around* all your controls, and then filter with a condition. Something like:

<xf:action
  ev:event="xforms-value-changed"
  ev:observer="my-group-around-controls"
  if="some condition here but I am not sure which condition is yours">
    <xf:send submission="id of your submission"/>
</xf:action>

-Erik
Reply | Threaded
Open this post in threaded view
|

Re: Problem with action on event:xforms-change

pumbosha
Thanks for response!

I think, that condition is something like:
xxf:instance('fr-form-instance')/*/*[name() = saxon:evaluate(instance('src'))] isChanged

but how can I write this in xforms
Reply | Threaded
Open this post in threaded view
|

Re: Problem with action on event:xforms-change

Alessandro  Vernet
Administrator
Hi Tom,

What you were trying to do in your first example in this thread looked like listening on a "value changed" event on a node in an instance. But XForms doesn't work this way: xforms-value-changed comes from the control whose value has changed, not the node in the instance.

In instance('src') you have the name of the element in the instance, e.g. first-name, because the element is <first-name/>. Is the form created with Form Builder? If it is, then the id of the control will be first-name-control, i.e. the name with the -control postfix. So you should be able to do the test with something like:

    if="event('xxf:targetid') = concat(instance('src'), '-control')"

While looking for a solution, you might want first to put not if="...", and have an <xf:message> to see if the event handler is called, at all, and then when it is, make it show the value of event('xxf:targetid') and instance('src') to check they are what you expect.

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

Re: Problem with action on event:xforms-change

pumbosha
Thank You! I'm going to try this solution

regards