8
$\begingroup$

How can the user enter specific numbers to a an already existed list using InputField, for example:

list1 = {{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}}

and the user wants to input 55 instead of 5, and 88 instead of 8.

Another example:

list = {};

DynamicModule[{x},
  Column[
    {InputField[Dynamic[x], String], 
     Dynamic @ 
       Refresh[If[x != "", AppendTo[list, x]; x = "";]; "", TrackedSymbols :> {x}], 
     Button["Reset", list = {}]}]] 

Dynamic[list]

The previous code allows the user to input numbers into a new list (by pressing Tab after writing them in the input field). I want the same way of entering numbers, but into an already existing list.

Your help is highly appreciated

$\endgroup$
3
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$
    – Michael E2
    Jul 30, 2016 at 22:26
  • $\begingroup$ How general a list do you expect to be handled? Will the lists be constrained to being matrices as you show in your example? Or do you want to be able to edit lists of arbitrary shape? $\endgroup$
    – m_goldberg
    Jul 30, 2016 at 23:50
  • $\begingroup$ Thanks for your reply... yes to a matrix $\endgroup$
    – Mark
    Jul 30, 2016 at 23:52

2 Answers 2

9
$\begingroup$

The simplest way is just

data = {{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}};
InputField[Dynamic[data]]

input

Dynamic[data]

{{1, 2, 3, 4, 55}, {6, 7, 88, 9, 10}}

$\endgroup$
1
  • $\begingroup$ Thank you so much but is there a way to do it by using the indices of the list? $\endgroup$
    – Mark
    Jul 31, 2016 at 7:59
6
$\begingroup$

Perhaps, something like:

inpF = DynamicSetting[Map[InputField[#, FieldSize -> 2, Alignment -> Center]&, #, {-1}]] &;

Use it as (Ctrl+Shift+Enter to evaluate in place after highlighting the right hand side):

enter image description here

$\endgroup$
3
  • $\begingroup$ thanks for your reply.. but the user should make this change by using InputField not manually. $\endgroup$
    – Mark
    Jul 30, 2016 at 22:52
  • 1
    $\begingroup$ @Mark, welcome to mma.se. I don't understand using InputField not manually. $\endgroup$
    – kglr
    Jul 30, 2016 at 23:01
  • $\begingroup$ I added another example to my question. Please check the new modification $\endgroup$
    – Mark
    Jul 30, 2016 at 23:18

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.