Problem with onFocusGained

Questions, tips and tricks and techniques for scripting in Servoy

Problem with onFocusGained

Postby tommygill » Tue Aug 17, 2010 9:58 pm

Hi All

A small difficulty here. Table A keeps track of donations & table stores details for these donations. A single donation may have more than one detail. When detail is being created, the amount of the donations is stored in a global variable(global.donation_amount). Another global variable(global.don_detail_amt) is also created with a default value of "0". On the detail form, when tabbing into the detail_amount field a onFocuseGained method is triggered, putting the default value (global.donation_amount) in it.

Code: Select all
function set_Detail_Amount() {
   if(globals.don_detail_total_amt < 1){
      detail_amount = globals.don_amount;
   }
   else if(globals.don_detail_total_amt > 0 && globals.don_detail_total_amt < globals.don_amount){
      detail_amount = globals.don_amount - globals.don_detail_total_amt;
   }
   elements.fld_amount.selectAll();
}

The data in the detail_amount field is then changed (if necessary). When tabbing out of the detail_amount field a onFocusLost method is triggered, displaying the appropriate button.

Code: Select all
function set_Buttons() {
   globals.don_detail_total_amt = (globals.don_detail_total_amt + detail_amount);
   if(globals.don_detail_total_amt != globals.don_amount){
      elements.btn_do_another_detail.visible = true;
      elements.lbl_do_another_detail.visible = true;
   }
   else{
      elements.btn_done_with_detail.visible = true;
      elements.lbl_done_with_detail.visible = true;
   }
   application.updateUI();
}

This works fine in 3.5.x but in 5.2, although the value in the detail_amount field can be changed, the value that the method sees never changes, ie: if the onFocuseGained method puts a value of 300, and the user changes it to 100, the form shows 100 but the method only sees 300. I observed this by watching the variables in the debug mode.

If I remove the onFocuseGained method then the onFocusLost method works properly. but this removes the important error checking portion of the onFocuseGained method.

I know this is wordy but i don't know how else to explain it. Thanks for your assistance.
Tom

Mac OS X 10.6.7
Servoy version 5.2.0 -build 997
Java Version 1.6.0_20
User avatar
tommygill
 
Posts: 110
Joined: Thu Jan 27, 2005 1:38 pm
Location: Columbus, Indiana, USA

Re: Problem with onFocusGained

Postby jcompagner » Wed Aug 18, 2010 12:30 pm

can you make a sample solution for this and attach it to a case?
This can be pretty tricky.

Focus events are not really there for datachanges (thats why we have ondatachange)
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8884
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Problem with onFocusGained

Postby tommygill » Wed Aug 18, 2010 4:13 pm

Hi Johan

Focus events are not really there for datachanges (thats why we have ondatachange)


This is true. In this case the data needs to be changed about 10% of the time. Thus the need for the onFocusLost trigger. One of the test was to take the onFocusGained method and trigger it with a onDataChage event earlier on the form. The results was the same.
Tom

Mac OS X 10.6.7
Servoy version 5.2.0 -build 997
Java Version 1.6.0_20
User avatar
tommygill
 
Posts: 110
Joined: Thu Jan 27, 2005 1:38 pm
Location: Columbus, Indiana, USA

Re: Problem with onFocusGained

Postby tommygill » Wed Aug 18, 2010 4:36 pm

Case submitted. #313408
Tom

Mac OS X 10.6.7
Servoy version 5.2.0 -build 997
Java Version 1.6.0_20
User avatar
tommygill
 
Posts: 110
Joined: Thu Jan 27, 2005 1:38 pm
Location: Columbus, Indiana, USA

Re: Problem with onFocusGained

Postby tommygill » Wed Aug 18, 2010 6:22 pm

After some further testing I found a workaround by adding an invisible field and switching the onFocusLost method to onFocusGained of the invisible field.
Tom

Mac OS X 10.6.7
Servoy version 5.2.0 -build 997
Java Version 1.6.0_20
User avatar
tommygill
 
Posts: 110
Joined: Thu Jan 27, 2005 1:38 pm
Location: Columbus, Indiana, USA


Return to Methods

Who is online

Users browsing this forum: No registered users and 4 guests