1
$\begingroup$

Writing:

fct[input_, output_, type_] := Module[{}, DialogInput[DialogNotebook[ {TextCell[input], InputField[Dynamic[output], type], DefaultButton[DialogReturn[output]]}, Background -> Green, Magnification -> 1.5]] ]; list = ConstantArray[0, 10]; For[i = 1, i <= 10, i++, Clear[msg]; fct["Insert number:", msg, Number]; list = ReplacePart[list, i -> msg] ] 

through a mask it is possible to populate list.

However, if the first request is entered 1, at the second request I would not like the box to be empty, but contain 1, which can only be changed if desired.

Is it possible to do this by maintaining the structure proposed above?

Thank you!

$\endgroup$
1
  • 1
    $\begingroup$ What if the first is 2? Should the second be empty? Or should it always be initialized to the previous value? $\endgroup$ Commented Mar 1, 2018 at 19:47

1 Answer 1

3
$\begingroup$

This is how I'd do it:

fct[input_, init_, type_: Number] := DialogInput[ {var = init} , Pane[ Column[ { TextCell[input] , InputField[Dynamic[var], type, System`BoxID -> "number"] , DefaultButton[DialogReturn[var]] } ] , ImageMargins -> 5 ] , Background -> Green , Magnification -> 1.5 , NotebookDynamicExpression :> (Refresh[ FrontEnd`MoveCursorToInputField[EvaluationNotebook[], "number"] , None ]) ]; 

and now just:

list = Rest@NestList[ fct["Insert number:", #] &, 0, 10 ] 

More about MoveCursorToInputField in 152536 and 1454 but it is not relevant here.

$\endgroup$
1
  • 1
    $\begingroup$ @TeM yes, you can do it your way but since you are replacing parts of list later anyway I just skipped this part and you generate list directly. $\endgroup$ Commented Mar 2, 2018 at 10:00