Subject Re: Reqired fill
From Charlie <tm@tc.com>
Date Tue, 01 Jun 2021 18:35:57 -0400
Newsgroups dbase.getting-started

OK..  Yes the trim did it.  I should have known better.

I ended up doing this...

function ENTRYFIELD4_onChange()
           if len(trim(form.entryfield4.value)) < 5
                   msgbox( " Invalid Input!" )
                        form.entryfield4.value = ""
                        form.auctopen1.rowset.fields["locate_a"].value = ""
                endif
      return

The valid is cool but it seemed to freeze the form until the problem was resolved which was frustrating.  is there a way around that?  

Thanks much!

Ken Mayer Wrote:

> On 6/1/2021 12:59 PM, charlie wrote:
> > Sorry...  Here is the code:
> >
> > if len(form.entryfield4.value) < 5
> >                    msgbox( " Sorry" )
> >                         form.auctopen1.rowset.fields["locate_a"].value = ""
> >                 endif
> >
> > Doesn't seem to work.
>
> onChange only fires after the user exits the entryfield, first off. So
> it doesn't fire as they type (good thing).
>
> When you create the form, and you set the picture, a value is also set,
> even if you empty the value in the inspector, it is set to "  -  " --
> hence, the length is *always* five ... The problem is that onChange will
> still let you move off the entryfield. If you use valid, it forces the
> user to enter the correct number of digits.
>
> Using valid is a much better tool for this if the user ** MUST ** enter
> the correct number of digits, the only concern is that they may not be
> able to do anything else, including abandon the rowset changes ... See
> attached form ...
>
> Ken
>
> --
> *Ken Mayer*
> Ken's dBASE Page: http://www.goldenstag.net/dbase
> The dUFLP: http://www.goldenstag.net/dbase/index.htm#duflp
> dBASE Books: http://www.goldenstag.net/dbase/Books/dBASEBooks.htm
> dBASE Tutorial: http://www.goldenstag.net/dbase/Tutorial/00_Preface.htm
> dBASE Web Tutorial: http://www.goldenstag.net/dbase/WebTutorial/00_Menu.htm
>
> ** END HEADER -- do not remove this line
> //
> // Generated on 06/01/2021
> //
> parameter bModal
> local f
> f = new TestValidForm()
> if (bModal)
>    f.mdi = false // ensure not MDI
>    f.readModal()
> else
>    f.open()
> endif
>
> class TestValidForm of FORM
>    with (this)
>       metric = 6        // Pixels
>       height = 352.0
>       left = 222.0
>       top = 290.0
>       width = 551.0
>       text = ""
>    endwith
>
>    this.TEXT1 = new TEXT(this)
>    with (this.TEXT1)
>       height = 22.0
>       left = 20.0
>       top = 12.0
>       width = 477.0
>       text = "Test validity of input ... "
>    endwith
>
>    this.ENTRYFIELD1 = new ENTRYFIELD(this)
>    with (this.ENTRYFIELD1)
>       onChange = class::ENTRYFIELD1_ONCHANGE
>       height = 22.0
>       left = 22.0
>       top = 58.0
>       width = 59.0
>       picture = "99-99"
>       value = "  -  "
>    endwith
>
>    this.ENTRYFIELD2 = new ENTRYFIELD(this)
>    with (this.ENTRYFIELD2)
>       valid = class::ENTRYFIELD2_VALID
>       height = 22.0
>       left = 141.0
>       top = 58.0
>       width = 56.0
>       picture = "99-99"
>       value = "  -  "
>       validRequired = true
>       validErrorMsg = "Enter all four digits"
>    endwith
>
>    this.TEXT2 = new TEXT(this)
>    with (this.TEXT2)
>       height = 22.0
>       left = 22.0
>       top = 93.0
>       width = 84.0
>       text = "onChange"
>    endwith
>
>    this.TEXT3 = new TEXT(this)
>    with (this.TEXT3)
>       height = 22.0
>       left = 141.0
>       top = 93.0
>       width = 84.0
>       text = "valid"
>    endwith
>
>
>    function ENTRYFIELD1_onChange()
> ? "Entryfield2: " + len( trim(this.value) )
>       if len( trim(this.value) ) < 5
>          msgbox( "Please enter all four digits!", "Invalid entry", 16 )
>          form.entryfield1.setFocus()
>       endif
>    return
>
>    function ENTRYFIELD2_valid()
>       bReturn = true
> ? "Entryfield2: " + len( trim(this.value) )
>       if len( trim(this.value) ) < 5
>          bReturn = false
>       endif
>    return bReturn
>
> endclass
>