Tuesday, January 29, 2013

Re: Dirty Form Flag in GWT or basically how to identify if in the form if there are any unsaved changes

The GWT Editor Framework does stuff with isDirty().  But by default it just compares your UI fields to the underlying model.  So that won't cover your cases 1 and 2.  You'd need to add some custom code to handle those cases.  The only way I can think to do that is by listening for events.

WIth UIBinder it wouldn't be too too bad... something like:

@UiHandler(value = {"tbox1", "tbox2", ... "tboxn"})
public void onTextBoxBlur(BlurEvent e) {
  //set dirty flag ...

that would listen for your blur event from all those textboxes.

Another thought would be to subclass textbox and handle it in there by adding an isDirty() flag

On Tuesday, January 29, 2013 1:26:29 PM UTC-8, BM wrote:
I have a form in GWT and I want to capture an event similar to dirtyform flag in JQuery. Basically I want to understand if any of the form data has been changed. The requirement is pretty simple here. I am NOT looking for if the data has been actually been modified but just to find out if they touched my form data by any way.

So let's say if my form has one GWT Textbox and one ListBox. For me the form data is changed with any of the following condition:

1) If the user changes the value inside Textbox and revert it back to previous original value. 
2) The user changes the default selection of ListBox to new selection but changes back to default selection.
3) If the user changes the value inside Textbox to a new value.
4) The user changes the default selection of ListBox to new selection.

The form data is not changed if the user just views the form but did not change any of the values in the Widgets at all. 

One way I thought would be to use onChange event and set a local flag hasDataChanged to true. Once the flag hasDataChanged has been set to true then don't reset it as it means the user touched the form. Based on the value of flag hasDataChanged show an alert message when navigating away from the page. 

But my problem is that if there are more GWT user interaction widgets (let's say 15 TextBox, 5 ListBox), the UI will fire onChanged Event every time. Plus I have to add onChange event handler to all of my GWT widgets. 

Perhaps there is a better way to do handle this. May be on view level if there is a single event I can assign which knows if any of GWT widgets been touched by the user? 

Any help would be appreciated!

You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment