6

A couple of versions of Mathematica ago there was discussion of how one can set focus on a particular input field:

How to set focus of a dialog window?

http://community.wolfram.com/groups/-/m/t/489107

Are any additional methods of accomplishing this possible in more recent versions of Mathematica?

Kuba
  • 136,707
  • 13
  • 279
  • 740
user90346
  • 355
  • 1
  • 4

1 Answers1

3

So to complement Kuba's answer, digging in the CloudObject source code (because there's that auth dialog) you find that even they still use the BoxID system. Look at:

FileNameJoin@{
  PacletFind["CloudObject"][[1]]["Location"],
  "Kernel",
  "Dialogs.m"
  }

where you'll find:

inptFld[dyn:Dynamic[expr_], boxid_, fldtype_, opts:OptionsPattern[]] := InputField[Dynamic[expr], fldtype, 
    ContinuousAction -> True,  
    System`BoxID -> boxid, 
    ImageSize -> {Full, Automatic},
    BaseStyle -> {
        FontFamily -> $BaseFontFamily,
  FontWeight -> "Regular",
  FontColor -> $InputTextColor,
        FontSize -> $InputFieldFontSize 
    },
    opts];

But apparently there is now this:

FrontEnd`MoveCursorToInputField

to be used like:

CreateDialog[
 inptFld[Dynamic[a], "asd", String],
 NotebookDynamicExpression :> (
   Refresh[
    FrontEnd`MoveCursorToInputField[EvaluationNotebook[], "asd"], None]
   )
 ]
b3m2a1
  • 46,870
  • 3
  • 92
  • 239
  • 1
    Pity this does not work: CreateDialog[DynamicName[InputField[Dynamic[a], String], "asd"], NotebookDynamicExpression :> (Refresh[ FrontEnd`MoveCursorToInputField[EvaluationNotebook[], "asd"], None])] – Kuba Sep 07 '17 at 10:24