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.