I have a little query over the Itemchanged event of datawindow. Within a
datawindow, I have a number of fields that need to be validated on users'
input. To achieve this, instead of putting my validation function at the
end of the process (i.e. pfc_save) I place it in Itemchanged event of the
datawindow so that once the user types in a value and presses tab key to
lose focus from that field, Itemchanged event will be triggered right away,
hence the validation function will be executed as well. One particular
problem with this operation in Itemchanged event that I found out is, for
instance, a user types in an invalid value in a column field, as the focus
loses the function works perfectly and prompts the user an error message
for re-input as intended. However, assume the user, by mistake, types in
the same value, which of course is invalid, the validation function is not
triggered this time for the reason that the Itemchanged event has not been
triggered at all. That looks absolutely reasonable, how could you expect
the Itemchanged event to perform as the value is exactly the same as the
previous one? It is fine with me. The question is how can I activate my
validation function in Itemchanged event even though there's no change in
value that user has typed in? Or if is there any way to get round this
problem? I'd be pleased to have your valuable suggestions.
Thanks for your kind attention
Lawrence
2 thoughts. In the itemfocuschanged event you could call accepttext
to do validation. Second, in the itemchanged event, if validation
fails, reset the column back to the data retrieved from the db.
Something like
this.SetItem(row,ls_colname,this.GetItemxxx(row,ls_colname,Primary!,true))
Larry Cermak [Team Powersoft] | Moderator forums.powersoft.com.database
Branick Consulting,Inc. | Moderator forums.powersoft.com.powerscript
lce...@branick-inc.com | www.branick-inc.com (PowerBuilder tips & techniques)
this.Modify("<colname>.ValidationMsg='<your error message>'")
return 1
HTH
Simon
Lawrence wrote in message <01bdc1a7$c498f660$c3e88cca@aslhk>...
>Dear all,
>
>I have a little query over the Itemchanged event of datawindow. Within a
>datawindow, I have a number of fields that need to be validated on users'
>input. To achieve this, instead of putting my validation function at the
>end of the process (i.e. pfc_save) I place it in Itemchanged event of the
>datawindow so that once the user types in a value and presses tab key to
>lose focus from that field, Itemchanged event will be triggered right away,
>hence the validation function will be executed as well. One particular
>problem with this operation in Itemchanged event that I found out is, for
>instance, a user types in an invalid value in a column field, as the focus
>loses the function works perfectly and prompts the user an error message
>for re-input as intended. However, assume the user, by mistake, types in
>the same value, which of course is invalid, the validation function is not
>triggered this time for the reason that the Itemchanged event has not been
>triggered at all. That looks absolutely reasonable, how could you expect
>the Itemchanged event to perform as the value is exactly the same as the
>previous one? It is fine with me. The question is how can I activate my
>validation function in Itemchanged event even though there's no change in
>hence the validation function will be executed as well. One particular
>problem with this operation in Itemchanged event that I found out is, for
>instance, a user types in an invalid value in a column field, as the focus
>loses the function works perfectly and prompts the user an error message
>for re-input as intended. However, assume the user, by mistake, types in
>the same value, which of course is invalid, the validation function is not
>triggered this time for the reason that the Itemchanged event has not been
>triggered at all.
I know you've gotten a couple of responses with suggestions about this problem,
but I don't understand how it's happening in the first place. As a test, I put
the following code in an ItemChanged event of a window built using the demo
database's employee table:
choose case dwo.name
case "emp_lname"
if len (data) < 5 then
MessageBox (parent.title, "Too short.")
Return 1
end if
end choose
I then put the cursor in the emp_lname item and typed 'abc' and hit tab. I of
course got the message "Too short" and the cursor was left in the item. I
deleted the 'abc' that I had typed and typed 'abc' again, and hit tab. Again I
got the message.
So basically, I'm not sure what you could be doing such that it would accept the
same invalid entry the second time around. Not to discount the suggestions
you've been given as 'workarounds', I think there might simply be something
wrong with the way you've coded or used the events.
---
Craig Wagner | E-mail: cwa...@metacorp.com
CPD Professional | Web: http://www.metacorp.com
Certified Powersoft Instructor | Phone: (503) 452-6343
Portland, OR USA |
Keeper of the PowerBuilder FAQ
http://www.teleport.com/~wagnerc/powerbuilder_faq.html
Hi Lawrence
What I usually do is define a user event ue_postitemchanged and write
all the validation code in that user event and in the itemchanged event
all I do is PostEvent. Of course with 5.0 onwards, I define the user event
arguments(parameters) same as that of itemchanged event, so that the
default arguments of itemchanged events are available in the user event.
Try this and just drop me a note if it works fine.
Kaushik Datta (http://www.castle.net/~kaudata)
This all works first time. So you key a value that's invalid as it already
exists in the filter buffer. You get a validation error message, and focus
stays in the invalid column. But then hit tab again, and itemchanged
doesn't fire, the offending value has already been accepted.
I eventually found that it was the call to RowsCopy that was causing the
problem, so I amended my code to loop through the filter buffer instead of
using RowsCopy, and this fixed it.
Simon
Craig Wagner wrote in message <35cb3592...@forums.powersoft.com>...
Lawerence,
I think the problem is the "bad" data is getting into the buffer and
therefore an itemchanged does not happen twice when the user types the
same value again...try this..on your u_dw control create an instance
variable is_errormsg...in your itemchanged do your validation and if it
fails set is_errormsg = 'field xyz must be less than 100'. then return
1. Now your in the itemerror event....overide and code the following
Integer li_Return
IF is_errormsg > '' then
//check to see if the window is closing if so do NOT show
//the error msg..you'll have to code your own func here
IF NOT parentwindow.YOURFUNCTION_getclosestatus() then
messagebox('your title',is_errormsg)
end if
is_errormsg = ''
li_return =1
Else
li_Return = Super::Event ItemError ( row, dwo, data )
END IF
RETURN li_Return
hth
Doug
hth
Doug
Doug S wrote in message <35E454...@mmm.com>...
Simon
Ken Ewald wrote in message ...