Quantcast

events and event handlers

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

events and event handlers

bwallis42
I am always somewhat mystified by what events occur, when, where they can be handled and how they propagate.

I've been reading some of the documentation and experimenting and have a simple case that doesn't seem to work as documented.

In the following body from a simple form, the three event handlers inside xh:body do not fire but the same ones inside fr:body do (the setvalue is missing in fr:body in this example but if you put it in there it does work).

but https://doc.orbeon.com/xforms/events-extensions-other.html#creating-keyboard-shortcuts-with-the-keypress-event says that you can catch the keypress event inside xh:body and has an example that I cannot get to work.

https://doc.orbeon.com/xforms/events-standard.html#top-level-event-handlers seems to say the same thing.

https://doc.orbeon.com/xforms/events-standard.html#using-the-evobserver-and-evtarget-attributes says that ev:observer is useful to register event handlers on elements which do not allow you to directly embed XML event handlers, but which elements are these that you cannot embed handlers in?

What am I missing here? I think I need a beginners guide to the event system but I don't seem to be able to find that. Is there a complete list somewhere of what events are dispatched and to what objects in the model?

Another difference is what events are fired and how are they handled while your form is being displayed in the builder? I want my form to behave differently in the builder than when being viewed, tested or edited.
 
I am working with a form that has a repeating grid that contains a few rows of other controls. The form when created or edited has an event handler that inserts a new entry into the model (we add a new entry every time it is edited and set previous entries to readonly) but in the builder you cannot see anything as there are 0 elements in the data. This makes it hard to edit the controls used in the grid except via the form source editor. I want to insert a single test entry that is only used for display while in the builder so I can see the controls and edit their properties. This code is destined to be in an XBL control in the long run but for the moment I just want to get the simple case working.

Obviously I am a bit lost with this and would appreciate any guidance. Thanks.

    <xh:body>
        <xf:setvalue event="xforms-ready" ev:observer="fr-form-model"
                     ref="instance('fr-form-instance')/section-1/control-1"
                     value="420"/>
        <xf:action event="xforms-ready" ev:observer="fr-form-model">
              <xf:message>hello world from ready outer</xf:message>
        </xf:action>
        <xf:action event="keypress" xxf:text="y">
              <xf:message>hello world from keypress outer</xf:message>
        </xf:action>
        <fr:view>
            <fr:body xmlns:xbl="http://www.w3.org/ns/xbl" xmlns:p="http://www.orbeon.com/oxf/pipeline"
                     xmlns:oxf="http://www.orbeon.com/oxf/processors">
                                 
                         <xf:action event="keypress" xxf:text="y">
                             <xf:message>hello world from keypress</xf:message>
                         </xf:action>
                         <xf:action event="xforms-ready" ev:observer="fr-form-model">
                             <xf:message>hello world from ready</xf:message>
                         </xf:action>
                <fr:section id="section-1-control" bind="section-1-bind">
                    <xf:label ref="$form-resources/section-1/label"/>
                    <fr:grid>
                        <xh:tr>
                            <xh:td>
                                <xf:input id="control-1-control" bind="control-1-bind">
                                    <xf:label ref="$form-resources/control-1/label"/>
                                    <xf:hint ref="$form-resources/control-1/hint"/>
                                    <xf:alert ref="$fr-resources/detail/labels/alert"/>

                                </xf:input>
                            </xh:td>
                            
                        </xh:tr>
                    </fr:grid>
                </fr:section>
            </fr:body>
        </fr:view>
    </xh:body>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: events and event handlers

Alessandro  Vernet
Administrator
Hi Brian,

You're looking at documentation for XForms, but you're adding code to a form that goes through Form Runner before getting to XForms, and Form Runner runs XSLT on your form, the output of which is fed to the XForms engine. The Form Runner XSLT was written to run on a form source produced by Form Builder, so in some cases it doesn't expect certain elements in certain places, and thus just doesn't copy them to the output.

Now, practically, I'd recommend you put all those handlers in the model. And even better, you can avoid editing the source of the form itself, and put that code in a separate file, that you reference from a property:

https://doc.orbeon.com/form-runner/advanced/custom-model-logic.html

Would this help?

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

Re: events and event handlers

bwallis42
Thanks for the explanation of the difference between a form runner form and a raw xform. Is there any documentation on what the form runner xslt does and what restrictions there are?

Can I run a raw xform without the translation? i.e one in which the keypress example from "Other Event Extensions" would work in?

thanks
brian...
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: events and event handlers

Alessandro  Vernet
Administrator
Hi Brian,

Thanks for the explanation of the difference between a form runner form and a raw xform. Is there any documentation on what the form runner xslt does and what restrictions there are?

Can I run a raw xform without the translation? i.e one in which the keypress example from "Other Event Extensions" would work in?

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

Re: events and event handlers

bwallis42
Hi Alex,
  Should there have been something else in that last post?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: events and event handlers

Alessandro  Vernet
Administrator
Hi Brian,

Sorry, here is what I meant to say:

The simple rule is: if you can, don't change the source of the form, and put your code in custom model logic. If you can't, we can talk about it, but this isn't the situation you're in ;).

Have you tried putting that code handling the keypress in custom model logic?

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