RavindraPatil


Hello,

Suppose an user is adding a record and he is on a field which needs validation. He tries for long time but can't enter valid data. So he wants to give up and exit from the form. But he cant click anywhere without entering valid data in that field.

In such case how to help the user to exit

pl. help




Re: how to escape from valid event

Paramu


Hi Ravindra,

Well.

On Your Form Load( ) or Form Init( )...You can assign a temproary exit something like the following manner...

ON KEY LABEL "ESC" exit

by PARAMU







Re: how to escape from valid event

surinder singh

on forms keypress or textbox's keypress event write this code

IF nkeycode = 27

THISFORM.Release

ENDIF







Re: how to escape from valid event

Markish

Hi,

"Return -1" returns the control to the previous control in the taborder. From there you can proceed to exit normally. Moreover a field can also have a default value (even may be blank) which is valid for that. For example when you are validating a txtbox

in th txtchoice valid even

Code Snippet

if this.value <> 'Q' && Not blank

if !inlist(this.value,'Y','y','n','N') && invalid

return 0

else

return 1

endif

else

return -1 && will return the control to the previous control...

endif

Hope you can work in this direction.

Best regards,

Markish






Re: how to escape from valid event

CetinBasoz

You can provide a 'Reset' or 'Cancel' etc button and move the code from valid to lostfocus. ie:

Code Snippet

* Lostfocus

if (this.Value < 20)

nodefault

this.SetFocus()

MessageBox( "Value should be over 20")

endif

With this approach, unlike "valid" user can click on buttons or close the form even if the data entered is not 'valid'. Do validation on button code when necessary (and IMHO it's a little bad retrictive experience for users to have the validation per control with valid).





Re: how to escape from valid event

Tamar E. Granor

If you have a button on the form with the Cancel property set to .T., then either the ESC key or clicking that button works to fire that button and puts keycode=27 in the keyboard buffer.

So, in your Valid method, you can check:

IF LASTKEY() = 27
RETURN .T.
ELSE
* Do your actual validity check
ENDIF

Tamar




Re: how to escape from valid event

Naomi Nosonovsky

Hi Ravindra,

I'm using the following as a method for my form (based on ideas from John Koziol and Cetin Basoz):

-----------------------------------------------------------------------------------------------------------------------------------------------------------------

********************************************************************
* Description.......: CancelValidation
* Calling Samples...:
* Parameter List....:
* Created by........: ideas by John Koziol /Cetin Basoz
* Modified by.......: NN
********************************************************************
local llReturn, loObject
local array laMouseObj[1]

llReturn = lastkey() = 46 && Alt+C - shortcut for Cancel button

if not m.llReturn
	amouseobj(laMouseObj,1) && object under mouse
	loObject = laMouseObj[1,1]

	if vartype(m.loObject) = "O"
		if not thisform.lValidateOnClose
			llReturn = thisform.releasetype = 1 or ;
				(inlist(lower(justext(sys(1272, m.loObject))),"cmdcancel", "cmdclose") ;
				and mdown()) && We're checking for Release type and Close button
		else
			llReturn = lower(justext(sys(1272, m.loObject))) = "cmdcancel" ;
				and mdown()
		endif
	else
		llReturn = .f.
	endif
endif

return m.llReturn

Now, in the textbox's valid I put:

if not thisform.CancelValidation()
* Continue with the valid logic
endif