6
$\begingroup$

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?

$\endgroup$
3
$\begingroup$

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]
   )
 ]
$\endgroup$
  • 1
    $\begingroup$ Pity this does not work: CreateDialog[DynamicName[InputField[Dynamic[a], String], "asd"], NotebookDynamicExpression :> (Refresh[ FrontEnd`MoveCursorToInputField[EvaluationNotebook[], "asd"], None])] $\endgroup$ – Kuba Sep 7 '17 at 10:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.