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.
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
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.
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.
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.