XForms/Event Logger

Motivation
You want to be able to see a record of events as they happen. This is a great way to learn about how XML Events work.

Method
We create an instance and add a element to that for each event.

Link to Example
Load XForms application

Sample Code
         Demonstration of XForms Event Logging  Input 1:     <xf:action ev:event="xforms-value-changed"> <xf:insert nodeset="instance('log')/event" at="last" position="after"/> <xf:setvalue ref="instance('log')/event[last]" value="'xforms-value-changed in input 1'" /> </xf:action> <xf:action ev:event="DOMFocusOut"> <xf:insert nodeset="instance('log')/event" at="last" position="after"/> <xf:setvalue ref="instance('log')/event[last]" value="'Out of input 1'" /> </xf:action> </xf:input>

<xf:input ref="instance('my-form')/element2" incremental="true"> <xf:label>Input 2:</xf:label> <xf:action ev:event="DOMFocusIn"> <xf:insert nodeset="instance('log')/event" at="last" position="after"/> <xf:setvalue ref="instance('log')/event[last]" value="'DOMFocusIn in input 2'"/> </xf:action> <xf:action ev:event="xforms-value-changed"> <xf:insert nodeset="instance('log')/event" at="last" position="after"/> <xf:setvalue ref="instance('log')/event[last]" value="'xforms-value-changed in input 2'" /> </xf:action> <xf:action ev:event="DOMFocusOut"> <xf:insert nodeset="instance('log')/event" at="last" position="after"/> <xf:setvalue ref="instance('log')/event[last]" value="'Out of input 2'" /> </xf:action> </xf:input>

<xf:input ref="instance('my-form')/element3" incremental="true"> <xf:label>Input 3:</xf:label> <xf:action ev:event="DOMFocusIn"> <xf:insert nodeset="instance('log')/event" at="last" position="after"/> <xf:setvalue ref="instance('log')/event[last]" value="'DOMFocusIn in input 3'" /> </xf:action> <xf:action ev:event="xforms-value-changed"> <xf:insert nodeset="instance('log')/event" at="last" position="after"/> <xf:setvalue ref="instance('log')/event[last]" value="'xforms-value-changed in input 3'" /> </xf:action> <xf:action ev:event="DOMFocusOut"> <xf:insert nodeset="instance('log')/event" at="last" position="after"/> <xf:setvalue ref="instance('log')/event[last]" value="'Out of input 3'" /> </xf:action> </xf:input> Event Log <xf:repeat id="results-repeat" nodeset="instance('log')/event"> <xf:output ref="."/> </xf:repeat>

Sample code 2
The above code doesn't work in the mozilla xforms plugin 0.8.5 with firefox 2.0.0.12 (it seems buggy dealing with instance). Try this code instead:

</xf:instance> <xf:action ev:event="xforms-ready"> <xf:setfocus control="field-1"/> <xf:insert nodeset="/data/event" at="last" position="after"/> <xf:setvalue ref="/data/event[last]" value="'Set Focus on Field-1'"/> </xf:action> </xf:model> Demonstration of XForms Event Logging <xf:input ref="/data/element1" incremental="true" id="field-1"> <xf:label>Input 1:</xf:label> <xf:action ev:event="DOMFocusIn"> <xf:insert nodeset="/data/event" at="last" position="after"/> <xf:setvalue ref="/data/event[last]" value="'DOMFocusIn in input 1'"/> </xf:action> <xf:action ev:event="xforms-value-changed"> <xf:insert nodeset="/data/event" at="last" position="after"/> <xf:setvalue ref="/data/event[last]" value="'xforms-value-changed in input 1'"/> </xf:action> <xf:action ev:event="DOMFocusOut"> <xf:insert nodeset="/data/event" at="last" position="after"/> <xf:setvalue ref="/data/event[last]" value="'Out of input 1'"/> </xf:action> </xf:input>

<xf:input ref="/data/element2" incremental="true"> <xf:label>Input 2:</xf:label> <xf:action ev:event="DOMFocusIn"> <xf:insert nodeset="/data/event" at="last" position="after"/> <xf:setvalue ref="/data/event[last]" value="'DOMFocusIn in input 2'"/> </xf:action> <xf:action ev:event="xforms-value-changed"> <xf:insert nodeset="/data/event" at="last" position="after"/> <xf:setvalue ref="/data/event[last]" value="'xforms-value-changed in input 2'"/> </xf:action> <xf:action ev:event="DOMFocusOut"> <xf:insert nodeset="/data/event" at="last" position="after"/> <xf:setvalue ref="/data/event[last]" value="'Out of input 2'"/> </xf:action> </xf:input>

<xf:input ref="/data/element3" incremental="true"> <xf:label>Input 3:</xf:label> <xf:action ev:event="DOMFocusIn"> <xf:insert nodeset="/data/event" at="last" position="after"/> <xf:setvalue ref="/data/event[last]" value="'DOMFocusIn in input 3'"/> </xf:action> <xf:action ev:event="xforms-value-changed"> <xf:insert nodeset="/data/event" at="last" position="after"/> <xf:setvalue ref="/data/event[last]" value="'xforms-value-changed in input 3'"/> </xf:action> <xf:action ev:event="DOMFocusOut"> <xf:insert nodeset="/data/event" at="last" position="after"/> <xf:setvalue ref="/data/event[last]" value="'Out of input 3'"/> </xf:action> </xf:input> Event Log <xf:repeat id="results-repeat" nodeset="/data/event"> <xf:output ref="."/> </xf:repeat>

Discussion
This uses the insert element to insert text into an event log.