Page 1 of 1

Validate get

Posted: Thu May 16, 2013 8:13 pm
by DonDrew
REDEFINE GET oSS_Num VAR cSS_Num ID 2103 of oFld:aDialogs[GenFldr] ;
Picture "@R ###-##-####" ;
valid ( !empty(cSS_Num ) ) ;
UPDATE

Need to be sure that the user can't save a blank value to cSS_Num. This used to work just fine in earlier versions of my system before I upgraded FWH/Harbour.

Is there a better way of testing for an empty field? I've oSS_Num:VarGet() and oSS_Num:Value() both methods test as empty.

Re: Validate get

Posted: Thu May 16, 2013 9:59 pm
by Rick Lipkin
Don

I would do your validation this way .. gives you more options ..

Rick Lipkin

Code: Select all

REDEFINE GET oSS_Num VAR cSS_Num ID 2103 of oFld:aDialogs[GenFldr] ;
Picture "@R ###-##-####" ;
valid ( _ChkSsn( cSs_num,oSs_num )) UPDATE


//--------------
Static Func _ChkSsn( cSs_num,oSsn_num )

Local Saying

If empty( cSs_num ) .or. cSs_num = "  "
   Saying := "SSN is a Required field"
   MsgInfo( Saying )
   oSs_num:SetFocus()
   Return(.f.)
Endif

Return(.t.)
 


 

Re: Validate get

Posted: Thu May 16, 2013 10:27 pm
by DonDrew
I did a poor job of describing my problem.

Since upgrading the FWH\Harbour the valid statement always finds cSS_Num empty, regardless of whatever the user may enter.

Re: Validate get

Posted: Thu May 16, 2013 10:38 pm
by cnavarro
DonDrew wrote:REDEFINE GET oSS_Num VAR cSS_Num ID 2103 of oFld:aDialogs[GenFldr] ;
Picture "@R ###-##-####" ;
valid ( !empty(cSS_Num ) ) ;
UPDATE

Need to be sure that the user can't save a blank value to cSS_Num. This used to work just fine in earlier versions of my system before I upgraded FWH/Harbour.

Is there a better way of testing for an empty field? I've oSS_Num:VarGet() and oSS_Num:Value() both methods test as empty.
VALID ( if (empty(cSS_Num ) , .F., .T. )) ;
So I work my

Re: Validate get

Posted: Thu May 16, 2013 11:13 pm
by FranciscoA
Hi,
I do the same as Mr. Rick, with something more:

The more secure method I have found to validate gets, it's when you press the "Accept" button, of the dialogue.

Why?, because if you have 3 gets, for example, and the user clicks the "Accept" button while him is in the second get, el third will be not evaluated.
Regards.

Re: Validate get

Posted: Fri May 17, 2013 1:03 am
by DonDrew
valid ( empty(cSS_Num ) )

valid ( if(empty(cSS_Num ),.F.,.T.) )

Both versions return False regardless of what may be entered by the user.

Re: Validate get

Posted: Fri May 17, 2013 8:31 am
by Antonio Linares
Don,

What FWH version are you using ?

Re: Validate get

Posted: Fri May 17, 2013 9:05 am
by DonDrew
Hi, Antonio.

FWH Ver 13.03

I found the solution this morning.

These did not work:
valid( !empty(cSS_NUM) )
valid( !empty(oSS_Num:Value()) )

This DID work:
oSS_Num:bvalid := { !empty(oSS_Num:Value()) }

Re: Validate get

Posted: Fri May 17, 2013 9:53 am
by nageswaragunupudi
This is working for me:

Code: Select all

#include "fivewin.ch"

function Main()

   local cVar  := Space( 8 )
   local oGet
   local oDlg

   DEFINE DIALOG odlg

   @ 10,10 GET oGet VAR cVar PICTURE "@R ###-##-###" SIZE 50,12 PIXEL OF oDlg ;
      VALID !Empty( cVar )

   @ 25,10 BUTTON "ok" SIZE 30,14 PIXEL OF oDlg

   ACTIVATE DIALOG oDlg CENTERED

   ? cVar

return nil
 
The get is validated when the focus is moved from the get object to another control of the dialog. The above program is working correctly as expected.

Get validation is not executed when there is only one get on the dialog.

The original code in the first posting should work as it is and as expected if there is another control on the dialog.

Re: Validate get

Posted: Fri May 17, 2013 10:08 am
by DonDrew
There are 19 controls on this one dialog.

Re: Validate get

Posted: Fri May 17, 2013 2:08 pm
by nageswaragunupudi
DonDrew wrote:There are 19 controls on this one dialog.
#1. Can you please compile and test the small program I posted and give your feedback if that is working as expected?

#2. Then if you still have problem, please post a small sample to reproduce your problem. A complete sample that we can compile and test at our end here. That will greatly help us to help you.