Adds a small, ungraded form for the reader to fill in identifying
information before starting a tutorial: name and email required, an ID
optional, by default. Unlike question(), nothing here is graded and
there is no model answer to reveal.
Arguments
- fields
A named character vector of field key/label pairs to collect, e.g.
c(name = "Full name:", section = "Section:").NULL, the default, gives the three fields of 'tutorial.helpers”sinfo_section.Rmd–name,emailand an optionalid– labelled in the page language (see the "Language" section ofquestion()). A field named"email"is additionally checked for an"@"character, regardless of whether it isrequired.- required
Character vector of keys (from
fields) the reader must fill in. Defaults to whichever of"name"and"email"are actually present infields, so ID is optional by default and supplying customfieldsdoes not require also supplyingrequired. A required field left blank, or an"email"field missing an"@", is flagged inline (on blur, and again when the button is clicked) and the form can't be submitted until it's fixed. Passing a key that is not infieldsis an error.- id
Stable identifier used to key the saved values in
localStorage. Defaults to"student-info"; change it if a single tutorial embeds more than onestudent_info()form.Button label while the form is open for editing.
NULL, the default, means the page language's "Submit".Button label while the form is locked on a submission. Clicking it reopens the form.
NULL, the default, means the page language's "Edit".
Details
The form has two states. While editing, the fields are open and the
button reads "Submit". A valid Submit saves the entry, locks the fields,
and switches the button to "Edit". Clicking Edit only reopens the fields
and switches the button back to "Submit", with a note that the change
isn't saved until the next Submit. So the button always tells the reader
whether what they see is what was received. Typing is kept as a draft in
the browser's localStorage, so a reload mid-edit loses nothing, but a
draft is never the answer: download_answers_button() reports only the
last submitted entry, and is blocked until the form is submitted. A
"reflection_editable" question() works the same way. Pair with
download_answers_button() so a reader can turn their work in.
Examples
student_info()
#> <div class="learnr2-info" data-learnr2-info="eyJpZCI6ImxlYXJucjItaW5mby1zdHVkZW50LWluZm8iLCJmaWVsZHMiOlt7ImtleSI6Im5h bWUiLCJsYWJlbCI6bnVsbCwicmVxdWlyZWQiOnRydWV9LHsia2V5IjoiZW1haWwiLCJsYWJl bCI6bnVsbCwicmVxdWlyZWQiOnRydWV9LHsia2V5IjoiaWQiLCJsYWJlbCI6bnVsbCwicmVx dWlyZWQiOmZhbHNlfV0sInN1Ym1pdExhYmVsIjpudWxsLCJlZGl0TGFiZWwiOm51bGx9">
#> <noscript>This form requires JavaScript.</noscript>
#> </div>
student_info(fields = c(name = "Full name:", section = "Section:"), required = "name")
#> <div class="learnr2-info" data-learnr2-info="eyJpZCI6ImxlYXJucjItaW5mby1zdHVkZW50LWluZm8iLCJmaWVsZHMiOlt7ImtleSI6Im5h bWUiLCJsYWJlbCI6IkZ1bGwgbmFtZToiLCJyZXF1aXJlZCI6dHJ1ZX0seyJrZXkiOiJzZWN0 aW9uIiwibGFiZWwiOiJTZWN0aW9uOiIsInJlcXVpcmVkIjpmYWxzZX1dLCJzdWJtaXRMYWJl bCI6bnVsbCwiZWRpdExhYmVsIjpudWxsfQ==">
#> <noscript>This form requires JavaScript.</noscript>
#> </div>