4

Let's say we create an input field as

InputField[]

After hitting enter, the input field appears in the output area below, however the focus in the notebook jumps straight to the next line, where a new cell can be created. Is there a way to create an InputField and immediately select it into focus upon creation (without having to click on it), so that text can be immediately typed into the InputField?

Kagaratsch
  • 11,955
  • 4
  • 25
  • 72

1 Answers1

4

You can assign a box id to an input field using BoxID -> "id" and use the function FrontEnd`MoveCursorToInputField to move the focus to the desired input field:

InputField[Null, BoxID -> "id"]
FrontEnd`MoveCursorToInputField[EvaluationNotebook[], "id"];

enter image description here

Another example:

Grid[{{InputField[Dynamic[x]], InputField[Dynamic[y], BoxID -> "ify"],
    InputField[Dynamic[z]]}}]
FrontEnd`MoveCursorToInputField[EvaluationNotebook[], "ify"]; 

![enter image description here

enter image description here

Alternatively, highlight the cell contents and use Ctrl + Shift + Enter to evaluate in place:

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896