Is there a way to make InputField[] compatible with RepeatingElement or a similar scheme of user interaction? The idea is to create an interface with many user defined variables, as many as the user sees fit to be exact.
Asked
Active
Viewed 103 times
1
Kuba
- 136,707
- 13
- 279
- 740
useranonis
- 435
- 2
- 7
1 Answers
4
Here's something to start with:
multiInput // ClearAll
multiInput[Dynamic[list_], type_: Number, def_: 0, opts___] :=
DynamicModule[{n = Length[list]},
Column[{
Button["+", AppendTo[list, def]; n++;],
Dynamic[
Grid[
Table[{
InputField[Dynamic[list[[#]]], type, opts],
Button["-", n--; list = Delete[list, #]]
} &@i, {i, n}]
, Alignment -> {Left, Center}],
TrackedSymbols :> {n}
]
}, BaseStyle ->
ButtonBoxOptions -> {ImageSize -> All, FrameMargins -> 5,
ContentPadding -> False}]
]
l = {};
multiInput[Dynamic@l]
Dynamic@l
Kuba
- 136,707
- 13
- 279
- 740

InputField's appear and disappear from the GUI panel with the click of a button. – useranonis Feb 15 '18 at 23:52TableandWith. I think the advanced dynamics tutorial in the docs has examples as well. – Mike Honeychurch Feb 15 '18 at 23:58