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. Defaults to name, email, and an optional ID, matching 'tutorial.helpers”s
info_section.Rmd. 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.
Button label while the form is locked on a submission. Clicking it reopens the form.
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 bWUiLCJsYWJlbCI6Ik5hbWU6IiwicmVxdWlyZWQiOnRydWV9LHsia2V5IjoiZW1haWwiLCJs YWJlbCI6IkVtYWlsOiIsInJlcXVpcmVkIjp0cnVlfSx7ImtleSI6ImlkIiwibGFiZWwiOiJJ RCAoaWYgcmVxdWVzdGVkIGJ5IHlvdXIgaW5zdHJ1Y3Rvcik6IiwicmVxdWlyZWQiOmZhbHNl fV0sInN1Ym1pdExhYmVsIjoiU3VibWl0IiwiZWRpdExhYmVsIjoiRWRpdCJ9">
#> <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 bCI6IlN1Ym1pdCIsImVkaXRMYWJlbCI6IkVkaXQifQ==">
#> <noscript>This form requires JavaScript.</noscript>
#> </div>