3
$\begingroup$

I would like to create a button 'ADD' that creates a new InputField each time the user clicks it.

I have tried something like this so far:

CreateWindow[
 DialogNotebook[
  TextCell["Click on + button to add more cells"]
   Button["ADD", InputField["Enter new input here"]]
 ]
]

The above method does not work. What would be a good and simple workaround for this problem?

$\endgroup$
3
$\begingroup$

Take a look at this resource function: https://resources.wolframcloud.com/FunctionRepository/resources/ListInputField

You can download the source notebook to see how it works.

$\endgroup$
3
$\begingroup$
cnt = {};
i=0;                                        (*added*)
CreateWindow[DialogNotebook[{
   "Click on ADD button to add more cells:",
   Dynamic@Column@cnt,
   Button["ADD", 
   i++;                                     (*added*)
   nm=ToExpression["a"<>ToString@i];        (*added*)
   AppendTo[cnt, 
    InputField[Dynamic@Evaluate@nm,         (*updated*)
               FieldHint->"Enter new input here"]]]   
   }, WindowSize -> 250, 
  WindowElements -> {"VerticalScrollBar", "StatusArea"}]]

enter image description here

The array of inputfields stores data in specially created variables a1, a2,....ax.

$\endgroup$
  • $\begingroup$ This almost does what I need. The problem that I face now is that the data that I input into those fields go only in to single variable and every time something new is entered, the variable updates. Is there a way to have the list of inputs to the fields stored in a list? $\endgroup$ – ssamm Apr 22 at 10:37
  • $\begingroup$ look at the updated version $\endgroup$ – Rom38 Apr 23 at 5:49

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.