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:

  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?


2 Answers 2

cnt = {};
i=0;                                        (*added*)
   "Click on ADD button to add more cells:",
   i++;                                     (*added*)
   nm=ToExpression["a"<>ToString@i];        (*added*)
    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.

  • $\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, 2019 at 10:37
  • $\begingroup$ look at the updated version $\endgroup$
    – Rom38
    Apr 23, 2019 at 5:49

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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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