A problem with Return in a field
Robert Brenstein
rjb at robelko.com
Tue Dec 12 05:40:35 EST 2006
On Dec 9, 2006, at 6:45 PM, Charles Szasz wrote:
>I have been working on my project since June. I almost done but I
>ran into an unexpected problem. When the user enters a raw score of
>two digits in a field and presses the Tab key, the cursor goes to
>the next edit field as it is supposed to do. When the user presses
>the Return key after entry of a two digit number, the number is
>pushed off to the left and the cursor remains in the field. This
>happens despite the autotab being set to true and no list behavior
>is checked.
>
>Here is a sample script from my project:
>
>
>ON keyDown whichKey
> IF whichKey is a number THEN
> IF the selection is not empty THEN delete the selection
> IF the length of me < 2 THEN
> pass keyDown
> ELSE
> answer information "Numbers cannot be longer than two digits."
> END IF
> END IF
>END keyDown
>
>ON closefield
> IF field "yrFld" > 4 AND field "yrFld" < 12 AND fld "msFld" > 62 THEN
> answer information "The total raw score is incorrect for a
>age of " && fld "yrFld" &" years!"
> put empty into me
> focus ON me
> ELSE
> IF field "yrFld" > 11 AND field "yrFld" < 20 AND fld "msFld" > 63 THEN
> answer information "The total raw score is incorrect for
>a age of " && fld "yrFld" &" years!"
> put empty into me
> focus ON me
> ELSE
> IF field "yrFld" > 19 AND field "yrFld" <60 AND fld
>"msFld" > 57 THEN
> answer information "The total raw score is incorrect
>for a age of " && fld "yrFld" &" years!"
> put empty into me
> focus ON me
> END IF
> END IF
> END IF
>END closefield
>
>
>The first script limits the input of 2 digit numbers only. The
>second script is flagging the possibility of an incorrect raw score
>being entered for certain ages. Some of the fields have a raw score
>limit based on the age of the child. For this example, children aged
>5 to 11 years, the total raw score can be only 62. for students in
>the age range of 12 to 19, the total is 63 and for adults (20 to 59
>years) the total is 57.
>
>The questions remains is why does the Return key does not act as a Tab key?
>
>Charles Szasz
>cszasz at mac.com
>
Charles,
If you want to trap return you need 4 handlers in your field
on returnKey
on enterKey
on returnInField
on enterInField
They complent each other. The simplest is for them to call a common
handler to simulate tabbing to the next field.
I also wonder whether you really, really need the keyDown handler if
you do input verification in closefield anyway. Just add a check for
a valid number there before other checks.
Robert
More information about the use-livecode
mailing list