Rebol Talk Forum  |  REBOL Discussions  |  REBOL View  |  Topic: Face field displays before error alert..
Pages: [1] Print
Author Topic: Face field displays before error alert..  (Read 518 times)
jfdutcher
Jr. Member
**
Offline Offline

Posts: 95


View Profile
Face field displays before error alert..
« on: June 14, 2004, 05:33:01 PM »

The code segment below is showing promise at allowing only digit entries...and some promise for limiting the number of digits to two per field.

It's interesting to me that the error alert about more than two digits pops up only as the 4th digit is keyed,
not when the 3rd one is keyed  Huh??

While the focus is properly returned to the offending field,
the re-displayed field then shows just one digit, not the three originally showing when the alert pops up.
[CODE]
Rebol[Title: "www.lotterychecker.com"]
key-event: func [face event] [
    if event/type = 'key [  
          ch: event/key
     if ch = 'left [return event]
     if ch = 'right [return event]
     if ch = #"^-" [return event]
     if not find "0123456789" ch [alert "Only digits can be entered" return none]
          test-box num1
     test-box num2
     test-box num3
     test-box num4
     test-box num5
     test-box num6
     test-box num7
    ]
    if event/type = 'close [
                    print "Removing event function"
                    remove-event-func :key-event
    ]
    RETURN event
]
test-box: func [numbox] [
    if (3 = length? numbox/text) [alert "Entry box allows only two digits" focus numbox
          show face return none]
]

insert-event-func :key-event    

lotto-layout: layout [backdrop green across tab tab
   title red "WWW.LOTTERYCHECKER.COM"
   below
   style numbox field 30x30 font [size:35]
   h1 {A tool with which you store, manage and check groups of               

   lottery ticket numbers:} across
   h1 blue "Select the game you wish to work with here --->"
   game: choice 200x45 "PowerBall" "New York Lotto" "Thunderball" "MegaMillions"
     return below
   h2 {Indicate the function you wish to perform by clicking one                

   radio button below:}
   across tab
   radbutchk: radio h2 blue {Check the winning number below against all my tickets:}
   return tab
   radbutadd: radio h2 blue "Add number below to my file for this game"
   return tab
   radbutdel: radio h2 blue "Delete number below from my file for this game"    
   return tab
   radbutver: radio h2 blue "Verify number below is on file for this game"
   return tab
   radbutlst: radio h2 blue {List all numbers for this game (no number need be entered

below):}
   return
   below
   h2 {Enter (6) two digit numbers below to reflect the requirements of             

   the game you selected above. Use the last box for entering winning bonus
   numbers for N.Y. Lotto, UK Nat'l. Lottery:}
   across
   num1: numbox "00" tab
   num2: numbox "00" tab
   num3: numbox "00" tab
   num4: numbox "00" tab
   num5: numbox "00" tab
   num6: numbox "00" tab
   num7: numbox "00"  
   return
   box red 700x3 return
   tab tab button 96x45 font [size: 25] "GO !!"  
   tab button 96x45 font [size: 25]"Reset" [clear-fields lotto-layout show lotto-layout]
]
focus num1
view lotto-layout
« Last Edit: June 14, 2004, 05:38:40 PM by jfdutcher » Logged
Sunanda
Full Member
***
Offline Offline

Posts: 110


View Profile
Face field displays before error alert..
« Reply #1 on: June 15, 2004, 11:40:44 AM »

You are only updating you field after the length test, not before.  So when you think t contains "123" you are testing on the old value "12"

Here's a simpler version of your code. It does field-exit validationn rather than key-press. That way it doesn't need the insert-events and so on.

(I'm not so keen on the alert box -- it gets in the way of fixing the error.  Maybe a message field instead?)

Code:
Rebol[Title: "www.lotterychecker.com"]

test-box: func [numbox] [

if any [error? try [to-integer numbox/text]
   2 < length? numbox/text
   numbox/text < "01"
   numbox/text > "59"
  ][
  alert join "Entry box allows only two digits 01-59 -- " numbox/text focus numbox
show face return none]
]


lotto-layout: layout [backdrop green across tab tab
title red "WWW.LOTTERYCHECKER.COM"
below
style numbox field 30x30 font [size:35]
     [test-box face]
h1 {A tool with which you store, manage and check groups of

lottery ticket numbers:} across
h1 blue "Select the game you wish to work with here --->"
game: choice 200x45 "PowerBall" "New York Lotto" "Thunderball" "MegaMillions"
return below
h2 {Indicate the function you wish to perform by clicking one

radio button below:}
across tab
radbutchk: radio h2 blue {Check the winning number below against all my tickets:}
return tab
radbutadd: radio h2 blue "Add number below to my file for this game"
return tab
radbutdel: radio h2 blue "Delete number below from my file for this game"
return tab
radbutver: radio h2 blue "Verify number below is on file for this game"
return tab
radbutlst: radio h2 blue {List all numbers for this game (no number need be entered

below):}
return
below
h2 {Enter (6) two digit numbers below to reflect the requirements of

the game you selected above. Use the last box for entering winning bonus
numbers for N.Y. Lotto, UK Nat'l. Lottery:}
across
num1: numbox "00" tab
num2: numbox "00" tab
num3: numbox "00" tab
num4: numbox "00" tab
num5: numbox "00" tab
num6: numbox "00" tab
num7: numbox "00"
return
box red 700x3 return
tab tab button 96x45 font [size: 25] "GO !!"
tab button 96x45 font [size: 25]"Reset" [clear-fields lotto-layout show lotto-layout]
]
focus num1
view lotto-layout
Logged
jfdutcher
Jr. Member
**
Offline Offline

Posts: 95


View Profile
Face field displays before error alert..
« Reply #2 on: June 15, 2004, 01:15:58 PM »

Thanks much..this shows much promise...it saves trying to isolate which keys to tolerate.

It is an oddity that if the nature of the 'error' is either keying an 'alpha', OR more than (2) digits...that
the alert box button must be clicked (3) times before it
actually goes away. If the 'error' is simply skipping over
a box (leaving '00' in it), the alert that arises needs to be clicked only once before closing.
When closed it advances focus  to the next box .... as opposed to the one causing the error.
Logged
Sunanda
Full Member
***
Offline Offline

Posts: 110


View Profile
Face field displays before error alert..
« Reply #3 on: June 15, 2004, 06:42:17 PM »

Those various pop-up type boxes are fairly buggy.....Best to avoid if at all possible.

Maybe try (as I suggested) just having an extra field on the main form for error messages.

And/or get clever and hide the GO button if the 6 fields are not all valid.
Logged
jfdutcher
Jr. Member
**
Offline Offline

Posts: 95


View Profile
Face field displays before error alert..
« Reply #4 on: June 15, 2004, 07:01:20 PM »

Will do !!!
Logged
Pages: [1] Print 
Rebol Talk Forum  |  REBOL Discussions  |  REBOL View  |  Topic: Face field displays before error alert..
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 21, 2008, 11:07:53 PM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2295 Posts in 593 Topics by 3766 Members
Latest Member: SpombSibpap

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc