views:

55

answers:

2

The question says it all. I want to know if it a good idea to manually call the accepttext() or pfc_accepttext to force powerbuilder to accept the values in the datawindow fields.

The reason behind this question is that I have a datawindow in a popup window which contains some fields. When the user enters values in that fields and presses an OK button, the datawindow is saved and the popup window is closed. When the ok button is clicked, the last field isn't properly accepting the input value. That's why I was thinking of manually firing accepttext() or pfc_accepttext event.

Any help will be appreciated!!!

Thanks.

+2  A: 

Yes, it is a very good idea to make sure a dw.accepttext() is fired prior to attempting to save any datawindow. Otherwise, like you pointed out, it may not save all the information the user enters unless they tab out of each field; which end users should not be expected to do.

For more complicated windows/objects you could create a simple function for this, such as wf_accepttext() which contains all the dw.accepttext() calls for each datawindow that will need to be updated. Then you can just call that function before you attempt to update your datawindows.

(Edit) Additional thoughts:

Terry's comment above reminded me of something I neglected to include in my initial answer. accepttext() returns -1 if a field's validation fails. So if you make a custom function to handle all your accepttext() calls, make sure you write it to handle this return code. Something such as this should be sufficient:

/* wf_accepttext() */
if dw_foo.accepttext() = -1 then return false
if dw_bar.accepttext() = -1 then return false
// etc..
return true

This way, at the top of your save function, let's call it wf_save(), you can do this:

/* wf_save() */
if not wf_accepttext() then return false
/* any other save validation and the dw.update() goes below here */

And in the event that something doesn't validate, wf_save() will bail, and your itemchanged event should have code to handle the rest.

offsound
+1  A: 

So, without seeing your code, it's not entirely clear why pfc_AcceptText isn't firing. However, what I can say is that pfc_AcceptText is an event defined by PowerBuilder Foundation Class's (PFC's) Logical Unit of Work service. While more than you'd generally ever want or need to know about PFC's LUW service can be found in my article, you've made me realize I've forgotten to document the intended entry point to this service. The intention (as you should be able to see in (pfcmain.pbl)pfc_w_master [closequery]) is that you fire the window's pfc_Save event, which will fire all the LUW events (e.g. pfc_Validation, pfc_PreUpdate) in the appropriate sequence.

Good luck,

Terry.

Terry
I believe Night Shade is referring to when you leave the cursor in a field after typing something, then immediately click on a button that tries to update that datawindow. At least on the older versions of Powerbuilder (11.5 in my case), unless you actually tab out of said field, the `accepttext` event won't be fired in time for the `dw.update()`.
offsound
PFC's LUW service *will* explicitly fire the AcceptText() before the Update(), when called properly; it's another advantage of using the service instead of coding your own. Mixing metaphors, using an updating service while half coding your own save routine, runs a lot of risks.
Terry