MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

simulating the tab keystroke in front end in InputField

  • To: mathgroup at
  • Subject: [mg101909] simulating the tab keystroke in front end in InputField
  • From: Michael <michael2718 at>
  • Date: Wed, 22 Jul 2009 06:23:26 -0400 (EDT)

I'm trying to create a simple input date field formatted MM/DD/YY.  I
want to have three separate InputField constructs, one for each part
of the date, but I don't want to have to hit tab to move to the next
field once I've entered the maximum number of characters, concurrent
with this I don't want to be able to enter more than the maximum
length (in this case two characters).  So I should, for example, be
able to type "070809" and have 07 filled into the month field, 08 into
the day field, and 09 into the year field.

Here is the code I have come up with so far.  Currently I am only
trying to auto-jump from the month to the day field, I have not done
the code to jump from day to month or to jump out of year.

f = (Module[{val = #1},
     If[StringLength[val] > 2,
      val = StringTake[val, 2]
     If[StringLength[val] == 2,
      FrontEndTokenExecute[FrontEnd`InputNotebook[], "Tab"]];
     iMonth = val
    ) &;
   InputField[Dynamic[iMonth, f], String, FieldSize -> {1, 1},
    ContinuousAction -> True], "/",
   InputField[Dynamic[iDay], String, FieldSize -> {1, 1}], "/",
   InputField[Dynamic[iYear], String, FieldSize -> {1, 1}]
   }] // Deploy

First off I had to use a FieldSize of "1" and I am not sure why.  The
docs say FieldSize is in ems, which doesn't make sense for text input
but that's ok, because maybe in an InputField it really is characters.
 But in any case it seems to be one off - 1 means two characters, 2
means three characters, etc.  No big deal, really.

But here is the real problem I am having... The FrontEndTokenExecute
statement is not working with "Tab"!  I am expecting this to cause the
cursor to jump to the next field, but it does not move at all.  I
tried replacing "Tab" with "New" just to make sure the rest of the
expression was ok, and sure enough it opens a new window as expected.

Is there something I am doing wrong?  I copied the code from a palette
in which it works perfectly...


  • Prev by Date: Re: Product::write : Tag List is Protected Error
  • Next by Date: Re: Re: Product::write : Tag List is
  • Previous by thread: Converting ANSO ISO Decimal BASIC to Mathematica 7
  • Next by thread: How to define real functions?