onDataChange() / hasRecordChanges() not working as expected

Questions, tips and tricks and techniques for scripting in Servoy

onDataChange() / hasRecordChanges() not working as expected

Postby paulc » Fri Aug 20, 2010 11:35 pm

Hi,

I am running into a problem with the databaseManager.hasRecordChanges() nor recognizing a field change correctly.

Our solution has forms that the user opens and then uses to edit the data in the database. If a user opens a form, edits a field, and immediately clicks on the "red x" / closes the form, the onHide method will not recognize databaseManager.hasRecordChanges(foundset) to be true until the user actually leaves the field.

I've tried to set focus to another field, in the onHide event, prior to running the databaseManager.hasRecordChanges(foundset) which doesn't seem to work either.

Code: Select all
/**
* onHide
*
*  @param {JSEvent} event the event that triggered the action
*
* @properties={typeid:24,uuid:"1e789f14-b06e-4376-94db-c4374c4c6ce7"}
*/
function onHide(event)
{
  controller.focusFirstField();
 
  var lv_ok =  databaseManager.hasRecordChanges(foundset); //this does not show correctly unless we place a break in our code (field loses focus)
 
  if ( lv_ok != true)
  { 
    var lv_msg = 'There are unsaved changes - either SAVE or ROLLBACK';
    forms.graphics_template_dialog.setup_dialog('nothing','Unsaved Changes',lv_msg,'Ok'); //this just sets up a formwith a text box with the msg and two buttons. and shows it
  }

  return lv_ok;
}




Is there a way to recognize that the data hase been modified? we need to prompt the user that changes have been made and that they either need to save or rollback changes before they can proceed.

Is this related in anyway to the fix in 5.2.1 as mentioned in my other post http://www.servoy.com/forum/viewtopic.php?f=3&t=14624?

Thank you
paulc
 
Posts: 55
Joined: Wed Feb 17, 2010 8:58 pm

Re: onDataChange() / hasRecordChanges() not working as expected

Postby jcompagner » Mon Aug 23, 2010 10:54 am

no this is not related to that other post.

Problem here is sequence of events. Your onhide method is called earlier then the fields has its onfocus lost (and calling loseFocus doesnt help, focus is always doen after your event is completely handled)

Make a case with a small example so that we can see if we can force a data "commit" before an onhide event.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: onDataChange() / hasRecordChanges() not working as expected

Postby paulc » Mon Aug 23, 2010 5:33 pm

HI Johan,

Thanks for the reply, case number is 314395.
paulc
 
Posts: 55
Joined: Wed Feb 17, 2010 8:58 pm

Re: onDataChange() / hasRecordChanges() not working as expected

Postby lvostinar » Mon Aug 30, 2010 11:03 am

paulc wrote:HI Johan,

Thanks for the reply, case number is 314395.


Cannot reproduce the problem from the sample you provided. Maybe is related to platform details (Java,OS) ? Also, can you reproduce with the sample that is attached ?
Laurian Vostinar
Servoy
lvostinar
 
Posts: 1062
Joined: Tue Feb 19, 2008 10:53 am

Re: onDataChange() / hasRecordChanges() not working as expected

Postby paulc » Tue Aug 31, 2010 6:30 pm

Using Servoy Version: 5.2.1 - build 999

JDK Information
java.vm.name=Java HotSpot(TM) Client VM
java.version=1.6.0_21
java.vm.info=mixed mode, sharing
java.vm.vendor=Sun Microsystems Inc.

Operating System Information
os.name=Windows XP
os.version=5.1
os.arch=x86

1) run the solution
2) click the test button
3) CLICK IN THE REMARK FIELD AT THE END TO SET FOCUS
4) type in the remark field (DO NOT CLICK ON ANYTHING ELSE)
5) While the remark field still has focus, click on the X to close the dialog
6) check the onhide event and the console.
databaseManager.hasRecordChanges(foundset); returns false

repeat the same steps, open the form, change the remark, close the form, still does not recognize the foundset has changes.

now repeat the same steps but with clicking the "Close" button, you will see that the foundset now recognizes changes.

----------------------------
If you change a value on the screen and do not lose focus on the changed field. Then press hide, in the onhide event .

In the test provide, enter values at the end of the remark. Then press the hide screen (X) on window, notice the hasRecordChanges does not return the correct value.

If you do the same except set focus to another field before you press the (X) the hasRecordChanges does return the correct value
paulc
 
Posts: 55
Joined: Wed Feb 17, 2010 8:58 pm


Return to Methods

Who is online

Users browsing this forum: No registered users and 10 guests