Starting with a fresh kernel, I evaluate the following:
Questions = {
(* Statement, Answer, Incorrect Answer *)
{"What is the capital of Switzerland?", "Bern", {"Vaduz", "Berlin", "Vienna"}},
{"Who is the king of the jungle?", "Lion", {"Giraffe", "Mouse", "Monkey"}},
{"2+2?" , "4", {"15", "13", "1e15"}}
} ;
Dynamic@Column@Questions
SetAttributes[DynamicInputField, {HoldFirst, Listable}];
DynamicInputField[var_, OptionsPattern[ContentType -> Expression]] :=
InputField[Dynamic[var], OptionValue[ContentType],
ContinuousAction -> True, ImageSize -> Full];
Dynamic@Grid[{
{"Statement", DynamicInputField[Questions[[1, 1]], ContentType -> String]},
{"Answer", DynamicInputField[Questions[[1, 2]], ContentType -> String]},
{Column[{"Incorrect Answers"}, BaselinePosition -> Top],
Column[DynamicInputField[#, ContentType -> String] & /@ Questions[[1, 3]],
BaselinePosition -> Top]
}
}, Alignment -> Left]
I must say that I took me a while to find out that I needed to set HoldFirst as an attribute for my function to work at least with the first two input fields. Nevertheless, the function does not work by mapping it into a list, i.e., the three last input fields send a error, the same one I had before I set HoldFirst as an attribute:
Set::setraw : Cannot assign to raw object Vaduz.>>
What am I doing wrong? I also tried the following:
Column[DynamicInputField[Questions[[1, 3]], ContentType -> String],
BaselinePosition -> Top]
Column[Table[
DynamicInputField[Questions[[1, 3, n]], ContentType -> String],
{n, 3}], BaselinePosition -> Top]
Giving the errors:
Part::pkspec1 : The expression n cannot be used as a part specification.>>
even when I put the Table inside a With[[n=n],...]
.
Moreover, why is not the same result in my two attempts of "solving" even though the function was set to be listable?