Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Pick form and validations - what am I missing
Message
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Title:
Pick form and validations - what am I missing
Miscellaneous
Thread ID:
01286808
Message ID:
01286808
Views:
66
OK - this shouldn't be this hard. I have a form with a data input field on it. To assist in entering proper information I have a pick routine that loads a pick form and allows the user to select the data value he wants to input. When I leave the field, I need to validate the selected data. I have a button on the form that launches the pick routine, and I don't want to perform validation of the field when the pick button is clicked. To make this work I have done the following:

- I added a property to the form called Picking. This defaults to .f.

- I moved validation of my values to the lostfocus event of my input textbox.

- In the LostFocus, I only perform validation if thisform.Picking = .f.

- In the When event of the input textbox, I set thisform.Picking = .f.

- In the When event of the pick button, I set thisform.Picking = .t.

- In the click event of the button, I launch my pick form, get the value returned, set focus back to the input text box, and set thisform.Picking = .f.

At this point I end up back in my text box and it seems that all would be well. However, when I leave the textbox now, somehow thisform.Picking = .t. and therefore the validation clause in my textbox.LostFocus gets skipped.

According to the event logger - here is what happens as the pick form is closed and the code in the pick button completes:
36106.255, formpick.Unload()
36106.286, formmain.text1.When()
36106.286, formmain.GotFocus()
36106.302, formmain.text1.GotFocus()
36106.302, formmain.text1.Message()
36106.317, formmain.command1.Valid()
36106.333, formmain.command1.When()
36106.380, formmain.Activate()
And here is the code from the pick button click event:
DO FORM pickvalue TO thisform.inputvalue
thisform.text1.SetFocus()
THISFORM.PICKING = .F.

thisform.Refresh
For some reason, as the focus comes back to my input window, the When event of the click button fires which sets the thisform.Picking flag back to .f.

This is the last thing that occurs before the application gives control back to the user. Then when I move to the next field, the validation doesn't occur.

I suppose I could go put in more flags and use the button valid event to set a flag that the button when event can read to know whether or not set the picking flag, but that seems a little silly.

Surely I am not the only person who wants to be able to use this type of functionality. How do I supress validation for a field on the screen when a button is pressed that launches another form to help select the value?

WHAT AM I MISSING!!!

Here is some code to duplicate the problem. If you start the program, and then immediately tab into the next field, the validation fires and "Yes" appears in the second input. If you start the form and use the button to enter a value, and then tab into the next field, you don't get the validation clause to fire because the form.picking flag ends up as .f.
PUBLIC o

o = CREATEOBJECT("formmain")
o.Show()




**************************************************
*-- Form:         formmain (c:\rest\test.scx)
*-- ParentClass:  form
*-- BaseClass:    form
*-- Time Stamp:   01/29/08 10:21:13 AM
*
DEFINE CLASS formmain AS form


  Top = 0
  Left = 0
  Height = 257
  Width = 408
  DoCreate = .T.
  Caption = "Data Input Test"
  validated = ""
  picking = .F.
  inputvalue = ""
  Name = "formMain"


  ADD OBJECT cmdclose AS commandbutton WITH ;
    Top = 216, ;
    Left = 296, ;
    Height = 27, ;
    Width = 84, ;
    Caption = "Close", ;
    TabIndex = 3, ;
    Name = "cmdClose"


  ADD OBJECT text1 AS textbox WITH ;
    ControlSource = "thisform.inputvalue", ;
    Height = 23, ;
    Left = 164, ;
    TabIndex = 1, ;
    Top = 56, ;
    Width = 100, ;
    Name = "Text1"


  ADD OBJECT text2 AS textbox WITH ;
    ControlSource = "thisform.validated", ;
    Height = 23, ;
    Left = 164, ;
    TabIndex = 2, ;
    Top = 111, ;
    Width = 100, ;
    Name = "Text2"


  ADD OBJECT label1 AS label WITH ;
    AutoSize = .T., ;
    Caption = "Enter a value:", ;
    Height = 17, ;
    Left = 76, ;
    Top = 59, ;
    Width = 76, ;
    TabIndex = 4, ;
    Name = "Label1"


  ADD OBJECT label2 AS label WITH ;
    AutoSize = .T., ;
    Caption = "Valid Value?", ;
    Height = 17, ;
    Left = 76, ;
    Top = 114, ;
    Width = 70, ;
    TabIndex = 5, ;
    Name = "Label2"


  ADD OBJECT command1 AS commandbutton WITH ;
    Top = 56, ;
    Left = 276, ;
    Height = 27, ;
    Width = 84, ;
    Caption = "Pick", ;
    TabIndex = 6, ;
    Name = "Command1"


  PROCEDURE cmdclose.Click
    thisform.Release
  ENDPROC


  PROCEDURE text1.LostFocus
    IF (thisform.picking = .f.)
      thisform.Validated = "Yes"
      thisform.Refresh
    ENDIF
  ENDPROC


  PROCEDURE text1.GotFocus
    thisform.picking = .f.
  ENDPROC


  PROCEDURE command1.When
    THISFORM.PICKING = .T.
  ENDPROC


  PROCEDURE command1.Click

    thisform.inputvalue = INPUTBOX("Please enter a value:")
    thisform.text1.SetFocus()
    THISFORM.PICKING = .F.

    thisform.Refresh
  ENDPROC


ENDDEFINE
*
*-- EndDefine: formmain
**************************************************
Paul R. Moon
Business Software Solutions
paul@businessoftware.com
Next
Reply
Map
View

Click here to load this message in the networking platform