catching changes

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

catching changes

Ronthe
What would be the best way to intercept any change to an instance? Is there an event that can be caught indicating the model instance has changed?
We'd like to give users the opportunity to save unsaved changes before browsing away from the application.



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: catching changes

Alessandro Vernet
Administrator
Ronny,

On 9/11/07, [hidden email] <[hidden email]> wrote:
> What would be the best way to intercept any change to an instance? Is there an event that can be caught indicating the model instance has changed?
> We'd like to give users the opportunity to save unsaved changes before browsing away from the application.

Yes, you can use xforms-value-changed event for this. In fact the
Government Forms example does exactly what you describe above. In
essence, it catches the xforms-value-changed event at the "top of the
page", stores in instance that there are unsaved data.

<xforms:action ev:event="xforms-value-changed">
    <xforms:setvalue model="common-model"
ref="instance('control-instance')/data-status">dirty</xforms:setvalue>
</xforms:action>

You can then use this information to enable a "save" button.

If you also want to have a confirmation dialog when users navigates
away from the page and the data isn't saved, you need to have a
control bound to the data-status node. Put an id on that control (say
"data-status"). Make the control hidden with some CSS (display: none).
Then put in JavaScript that looks like:

window.onbeforeunload = function() {
    if(ORBEON.xforms.Document.getValue('data-status') == 'dirty'){
        return "Data not saved, are you sure you want to go to another
without saving?";
    }
}

I hope this helps,

Alex
--
Orbeon Forms - Web 2.0 Forms, open-source, for the Enterprise
http://www.orbeon.com/



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws