Nodeset change event

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Nodeset change event

Vedha
This post was updated on .
Hello,

I like to know, if there is way in Orbeon to trigger event for a change in nodeset values. This nodeset value might not correspond to a UI component.

Consider a sample instance where a and b are the node elements and they hold different values. i have UI field for a in the form and i do not have a UI field for b. In this scenario, i like to trigger event for changes in b. Any suggestions for this.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Nodeset change event

Alessandro  Vernet
Administrator
Hi Vedha,

You can use the xxforms-value-changed event for this, documented under "Instance events" on:

http://doc.orbeon.com/xforms/events-extensions-events.html

Since you only want something to happen when a specific node changes, you'll want to add a test, like if="event('node') = instance()/a". Here is an example showing this in action:

https://gist.github.com/avernet/5235e158927cfad6e2ae

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

Re: Nodeset change event

Vedha
This post was updated on .
Great. It works. I also need a suggestion from you on this. I like to listen for value change in two different nodes of the instance.


Should i write two different action with different IF attribute one for each node?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Nodeset change event

Alessandro  Vernet
Administrator
Hi Vedha,

I'm glad this works. About doing something if either node A or node B is changed, it depends if you want to do the same or a different thing in each case.

- If the same thing, then you could write something like if="event('node') = (instance()/a, instance()/b)".
- If a different thing, then yes, you'll want to have to have 2 actions, since the content of the action will be different in each case.

Does this make sense?

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

Re: Nodeset change event

Vedha
Thanks for the great explanations. Its working great.

Few more questions, just to understand native xForms. Is it mandatory to use Orbeons change event here? Is there a native Xforms alternative for this?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Nodeset change event

Alessandro  Vernet
Administrator
Hi Vedha,

In XForms, only xforms-insert and xforms-delete are dispatched to the instance, and there is no xforms-value-changed or equivalent dispatched to the instance, thus Orbeon Forms adding xxforms-value-changed.

https://www.w3.org/community/xformsusers/wiki/XForms_2.0#Events_Overview

If you really had to do this in "pure XForms", you'd have to create a control bound to the node you're interested in, and somehow hide that control, e.g. with CSS but not with relevant="false()", otherwise it wouldn't get the event.

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

Re: Nodeset change event

Vedha
Wondering why XFORMS did not provide any such event handling, it looks more obvious in our code. Anyway i shall use Orbeon xxforms events. Its working good.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Nodeset change event

Alessandro  Vernet
Administrator
Hi Vedha,

About that event not being part of the spec, I don't think that there is any deep philosophical reason for that. The spec still has room to grow and improve, and some of those improvements come from companies and customers using XForms, and discovering shortcomings, which often first get implemented as extensions.

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

Re: Nodeset change event

Vedha
This post was updated on .
This logic is broken.

We have started implementing this logic in many places and now it looks broken.

For your example given

Just set the default value of 'a' as 1 and 'b' as 2,

Now, try to set the value of 'b' as 1. The xxforms-value-changed 'if' condition should only provide the values changes to 'a' node, this will now also be triggered for setting 'b' as 1.

From my understanding, if condition is not comparing the node but the values of the node. This problem happens when two elements of the instance hold same value(in this case it is 1 after button click).




<xh:html xmlns:xh="http://www.w3.org/1999/xhtml"
      xmlns:xf="http://www.w3.org/2002/xforms"
      xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
      xmlns:ev="http://www.w3.org/2001/xml-events"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:fr="http://orbeon.org/oxf/xml/form-runner">
    <xh:head>
        <xf:model>
            <xf:instance id="my-instance">
                <instance>
                    <a1>1</a1>
                    <b1>2</b1>
                </instance>
            </xf:instance>
            <xf:message event="xxforms-value-changed"
                        observer="my-instance"
                        if="event('node') = instance()/a1"
                        value="'Changed'"/>
        </xf:model>
    </xh:head>
    <xh:body>
        <xf:trigger>
            <xf:label>Set value</xf:label>
            <xf:setvalue event="DOMActivate" ref="b1">1</xf:setvalue>
        </xf:trigger>
    </xh:body>
</xh:html>

Message is triggered in this case if i set the value of 'b1'. Any suggestions. I have implemented this logic in many places in application.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Nodeset change event

Alessandro  Vernet
Administrator
Hi Vedha,

My bad: the comparison should should have read:

    event('node') is instance()/a

That is, using `is` instead of `=`. When using `=`, the operators will be atomized, and thus you'll be comparing whether the value in the node that changed is equal to the value in instance()/a, which might lead to false positives.


I've also attached an updated example along the lines of what you're describing that shows that `is` does the right thing in this case. You'll let us know if this works for you!

Alex

On Wed, Sep 7, 2016 at 3:14 PM, Vedha <[hidden email]> wrote:
This logic is broken.

We have started implementing this logic in many places and now it looks
broken.

For your example  given
<https://gist.github.com/avernet/5235e158927cfad6e2ae>

Just set the default value of 'a' as 1 and 'b' as 2,

Now, try to set the value of 'b' as 1. The xxforms-value-changed 'if'
condition should only provide the values changes to 'a' node, this will now
also be triggered for setting 'b' as 1.

From my understanding, if condition is not comparing the node but the values
of the node. This problem happens when two elements of the instance hold
same value(in this case it is 1 after button click).




<xh:html xmlns:xh="http://www.w3.org/1999/xhtml"
      xmlns:xf="http://www.w3.org/2002/xforms"
      xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
      xmlns:ev="http://www.w3.org/2001/xml-events"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:fr="http://orbeon.org/oxf/xml/form-runner">
    <xh:head>
        <xf:model>
            <xf:instance id="my-instance">
                <instance>
                     1
                    <b1>2</b1>
                </instance>
            </xf:instance>
            <xf:message event="xxforms-value-changed"
                        observer="my-instance"
                        if="event('node') = instance()/a"
                        value="'Changed'"/>
        </xf:model>
    </xh:head>
    <xh:body>
        <xf:trigger>
            <xf:label>Set value</xf:label>
            <xf:setvalue event="DOMActivate" ref="b1">1</xf:setvalue>
        </xf:trigger>
    </xh:body>
</xh:html>

Message is triggered in this case if i set the value of 'b1'. Any
suggestions. I have implemented this logic in many places in application.

--
View this message in context: http://discuss.orbeon.com/Nodeset-change-event-tp4661000p4661755.html
Sent from the Orbeon Forms community mailing list mailing list archive at Nabble.com.

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].

view.xhtml (1K) Download Attachment
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Nodeset change event

Vedha
Just checked this and it works fine. Issue resolved. :)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Nodeset change event

Alessandro  Vernet
Administrator
In reply to this post by Alessandro Vernet
Hi Vedha, very good, and thanks for confirming this.

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Loading...