A question a visitor answers with a line of text.
label is what the visitor is asked, and it is a template. placeholder
is the hint shown in the empty field, and it is a template too. required
says whether an empty response is acceptable and defaults to false.
format names a validation format this package knows - email is the one
the signup wizard uses - and the format's own check belongs to response
validation; what this type checks is that the name is one the package will
recognize when a response arrives, because an author who misspells a
format should be told while they are authoring rather than when a visitor
submits.
Three fields belong to a format rather than to the question, and each is
read only by the format that owns it. pattern is the regular expression
the pattern format holds a response to, and it has to match the whole
response; where the question asks for that format, whether the expression
compiles at all is checked here, for the same reason the format name is -
nothing a visitor could type would satisfy one that does not, so the author
is told while they are authoring rather than when a visitor submits. On a
question that does not ask for the pattern format, a pattern is a field
nothing consults and nothing here reads it. min and max are the bounds
the integer and number formats hold a response between. A question that
declares one without the format that reads it declares something nothing
consults.
iex> node = %{type: "text_question", key: "pin", label: "PIN", format: "pattern", pattern: "[0-9"}
iex> [finding] = Riddler.Screens.Type.TextQuestion.validate(node)
iex> finding.code
"document.invalid_pattern"
iex> Riddler.Screens.Type.TextQuestion.validate(%{type: "text_question", key: "email", label: "Work email", format: "email"})
[]
iex> node = %{type: "text_question", key: "email", label: "Work email", format: "e-mail"}
iex> [finding] = Riddler.Screens.Type.TextQuestion.validate(node)
iex> finding.code
"document.unknown_format"