# PlotRange with InputField in Manipulate

Trying to understand work of InputField in Manipulate. My example code is:

Manipulate[ListPlot[(ToExpression@list),
PlotRange -> {{Automatic, max}, Automatic}],
Control[{{list, "Range[10]", "List"},
InputField[#, String] &}], {{max, 10, "Max range"}, InputField}]


So, I have some list (here just Range[10] for simplicity), which can be entered by user in corresponding InputField and I want to control plotting range (max variable here). Now if I change Range[...] the plot range doesn't change, I suppose max should somehow become equal to Max@ToExpression@list. How to organize this?

Thanks.

As I understand the question, the OP would like the user to be able to control the upper limit of the horizontal axis; and would like max to be set to the maximum range whenever list is changed, after which the user can change max as desired. In that case, a typical approach is to use TrackingFunction to set the other variables. I thought it would be more efficient to have another hidden variable (no control) to be the actual list, since its value is needed in a couple of places.

Manipulate[
ListPlot[list, PlotRange -> {{Automatic, max}, Automatic}],
Control[{{str, "Range[10]", "List"},
InputField[#, String] &,
TrackingFunction -> (
(str = #;
list = ToExpression[str];
(* Optional: add check here, set flag if not a List *)
max = Length[list]) &)}],
{{max, 10, "Max range"}, InputField},
{{list, Range[10]}, ControlType -> None}
]

• Yes, this is exactly what I need, many thanks Michael! – Alx Jul 8 '19 at 1:36
• @Sam_1q You're welcome! – Michael E2 Jul 8 '19 at 3:19