A question a visitor answers by picking from a list of options.
label is what the visitor is asked, and it is a template. select is
"one" or "many", and it fixes the shape of the response: one option's
value under "one", a list of option values under "many".
answer_options is the list of options, in the order the visitor is shown
them. An option carries value and label. value is what the response
holds when the visitor picks that option: a string in the key shape
[a-z][a-z0-9_]*, so that a condition or a template compares a response
with it as written, and unique among this question's own options. It is not
a key, so two questions may both offer the same value. label is what the
visitor reads, and it is a template. Admission keeps exactly those two
fields of an option and drops any other, as it drops a node field a type
does not name.
style is a hint a renderer reads - radio or dropdown for one,
checkboxes or list for many - from an open set the renderer owns; what
this type checks is that it is a string. required defaults to false, and
true means the visitor picks at least one option. min_selections and
max_selections bound how many options a visitor picks, and they are read
only under select: "many". Each is a non-negative integer, a number with
no fractional part counting as one - a bound written 2.0 is admitted as
2. format is carried and never consulted: it is a field nothing reads,
whatever it names.
iex> node = %{type: "choice_question", key: "card_type", label: "Which library card would you like?", select: "one", answer_options: [%{value: "adult", label: "Adult card"}, %{value: "child", label: "Child card"}]}
iex> Riddler.Screens.Type.ChoiceQuestion.validate(node)
[]
iex> node = %{type: "choice_question", key: "pickup_branch", label: "Where will you collect your card?", select: "one", answer_options: [%{value: "riverside", label: "Riverside"}, %{value: "riverside", label: "Riverside (east entrance)"}]}
iex> [finding] = Riddler.Screens.Type.ChoiceQuestion.validate(node)
iex> {finding.code, finding.node_key}
{"document.duplicate_option_value", "pickup_branch"}