Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Disable Valid Method! 1

Status
Not open for further replies.

ZooMoo

IS-IT--Management
May 16, 2002
11
TH
How to disable or skip about valid method in textbox., if user press cancel key or press cancel command button. Someone show me a tip. cause i have terribled about programming avoid in this checking method module.

thk adv.
;)
 
ZooMoo

Put a condition to be met in the valid for example:

If lCondition = .t.
** Do the valid event
ELSE
** Do nothing
ENDIF



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Thanks, Mike Gagnon

Currently, I using the same at your suggestion, but i'm crazy to write it, if !empty() , if !lastkey() , if not and if not ....

Are u have a special tip for me.

Thk adv.
 
ZooMoo

That is the only way I can think of.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Let's start with the button.

The button has a mouseEnter and MouseLeave event. Create a property on the form named letmeout. Initial value is .F.

In the MouseEnter event place the following code:
THISFORM.letmeout = .T.

In the MouseLeave event place the following code:
THISFORM.letmeout = .F.

In the valid of the textbox place the following code:
If THISFORM.letmeout = .T.
RETURN .T.
ELSE
RETURN .F.
ENDIF

* You can also use the mouse position instead of a property.


As for the cancel key. I am not sure what key you mean, but typically it is the escape key. You can trap for most keys with the lastkey() function. Let's assume it is the escape key. Add the following code to the text valid event.

If THISFORM.letmeout = .T. OR LASTKEY() = 27
RETURN .T.
ELSE
RETURN .F.
ENDIF

Jim Osieczonek
Delta Business Group, LLC
 
Hi Jim

ThisForm.letmeout example of yours..

1. If the user clicks another textbox? Wwill let you out without validation, for all cases of mouse clicking on any other object. The very purpose of validation code will get failed.

2. Again, if the user left the mouse on the textbox and then tabs out.. ? Mouse leave event wont get fired.

As Mike Gagnon said, I do not see much option to leave the validation when another control is clicked, because it defeats the very purpose of validation by concept.

What can be done is...

Shift the entire validation code from the Valid event to LostFocus Event.. and then code it this way..

Text1.Valid
***********
No code here... shift to Lost focus event

Text.LostFocus
**************
IF EMPTY(This.Value)
IF 6 # MESSAGEBOX("Do you want to quit ?", 4+16)
NODEFAULT
ENDIF
ELSE
** myValidation code.. shifted from Valid event..
** instead of return .f. ... NODEFAULT
** example...
IF NOT myConditionMet
NODEFAULT
ENDIF
ENDIF

** DEFAULT is the default behaviour of leaving the field. So no need to put that piece of code.. to return .t.

:)

____________________________________________
ramani - (Subramanian.G) :)
When you ask VFP questions, please add VFP version.
 
Ramani,

I am not sure I am following you. I have it setup on a form. I cannot leave the text box unless my mouse is over the "quit" button.

The only shortfall I see is that if the mouse is just set over the button, without a click, it would allow the user to tab out of the textbox. Therefore, the code could use a bit of modification to include the MOUSE command just to ensure a click occurred, but other than that it should work fine.

Jim Osieczonek
Delta Business Group, LLC
 
Jimoo

I am sorry, I did not undestood you correctly earlier. Now I got your point. The mistake I did is that I imagined something like MouseEnter/Leave of the Text control. I took the word 'button' for the TextBox control. huh..

Yes. That is a clever method and that will work, though I did not test yet. To explain a bit, so that other readers dont make the same mistake I made..

1. Add a property to the form... let us say LetMeOut
and initialise the value to .f.

2. CmdExit.MouseEnter
THISFORM.letmeout = .T.

3. CmdExit.MouseLeave
THISFORM.letmeout = .F.

4. Text1 or which ever TextBoxes you want the valid not to test.. add the code..
If THISFORM.letmeout = .T.
RETURN .T.
ELSE
** Do the validation
** and then RETURN .F. or Return .T.
ENDIF

And to be frank, I like this idea. It is because, this can be set universal for all the controls in the form.

Star for you. :)

____________________________________________
ramani - (Subramanian.G) :)
When you ask VFP questions, please add VFP version.
 
Thanks ramani, and thanks for clarifying.

I should have done this one in code. It would have been easier to see in practice.

Jim Osieczonek
Delta Business Group, LLC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top