Skip to contents

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 – it is auto-saved to the browser's localStorage as the reader types and restored on their next visit, the same as every other field here. A confirmation button, matching the one on every question() in both style and behavior, gives the reader an explicit way to confirm their entry and see the required fields checked right away, instead of only finding out when they later try to download: it reads "Submit" until they successfully do, at which point it switches to "Edit" (like a "reflection_editable" question()) since any further click is revising an already-confirmed entry, not submitting for the first time. Pair with download_answers_button() so a reader can turn their work in.

Usage

student_info(
  fields = c(name = "Name:", email = "Email:", id =
    "ID (if requested by your instructor):"),
  required = intersect(c("name", "email"), names(fields)),
  id = "student-info",
  submit_button = "Submit",
  edit_button = "Edit"
)

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 is required.

required

Character vector of keys (from fields) the reader must fill in. Defaults to whichever of "name" and "email" are actually present in fields, so ID is optional by default and supplying custom fields does not require also supplying required. A required field left blank, or an "email" field missing an "@", is flagged inline (on blur, and again when the button is clicked) and blocks download_answers_button() until it's fixed. Passing a key that is not in fields is 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 one student_info() form.

submit_button

Button label shown before the reader has successfully confirmed their entry.

edit_button

Button label shown instead of submit_button from then on – mirrors question()'s edit_button for a "reflection_editable" question exactly, including persisting across a reload.

Value

A learnr2_info object, printed as an interactive HTML form.

Examples

student_info()
student_info(fields = c(name = "Full name:", section = "Section:"), required = "name")