Skip to content

pl-units-input element

Fill in the blank field that allows for numeric input and accompanying units.

Sample element

question.html
<pl-units-input answers-name="c_1" correct-answer="1m" atol="1cm"></pl-units-input>

Customizations

Attribute Type Default Description
allow-blank boolean false Whether an empty input box is allowed. By default, empty input boxes will not be graded (invalid format).
allow-feedback boolean true Whether to show detailed feedback from the autograder for incorrect answers (for example, stating whether a unit or magnitude specifically is incorrect). Feedback varies based on grading-mode.
answers-name string Variable name to store data in. Note that this attribute has to be unique within a question, i.e., no value for this attribute should be repeated within a question.
aria-label string An accessible label for the element.
atol string 1e-8 Absolute tolerance for comparison="relabs" and grading-mode="with-units". In grading-mode="with-units", the default value copies the units used in the correct answer, and custom values must include units.
blank-value string "" Value to be used as an answer if element is left blank. Only applied if allow-blank is true. Must be "" (empty string) or follow the same format as an expected user input.
comparison "exact", "sigfig", "decdig" or "relabs" "sigfig" How to grade. "relabs" uses relative (rtol) and absolute (atol) tolerances. "sigfig" use digits significant digits. "decdig" uses digits after decimal place, "exact" uses == and should only be used for integers. Attribute can only be set if grading-mode="exact-units"
correct-answer string See description Correct answer for grading. Defaults to data["correct_answers"][answers-name].
custom-format string Custom format specifier to use when formatting the submitted and correct answer after processing. By default, uses standard string conversion. A full description of the format can be found on the Pint documentation page.
digits integer 2 Number of digits that must be correct for comparison="sigfig" or comparison="decdig".
display "block" or "inline" "inline" How to display the input field.
grading-mode "with-units", "exact-units", or "only-units" "with-units" How to grade student submission. "only-units" only checks for the units input by the student. "exact-units" asks for a quantity with a specified unit. "with-units" is similar to "exact-units", but will automatically convert the units used by the given answer if possible.
initial-value string Initial value to prefill the input box the first time it is rendered.
label string A prefix to display before the input box (e.g., label="$F =$").
magnitude-partial-credit float Fraction of partial credit given to answers of correct magnitude and incorrect units when grading-mode="exact-units". Remaining fraction of credit given when units are correct, but magnitude is incorrect. Must be between 0.0 and 1.0. Partial credit is disabled if this is not set.
placeholder string String to override default placeholder text. The default placeholder gives information about the comparison type used.
rtol number 1e-2 Relative tolerance for comparison="relabs" and grading-mode="with-units".
show-help-text boolean true Show the question mark at the end of the input displaying required input parameters.
show-score boolean true Whether to show the score badge next to this element.
size integer 35 Size of the input box.
suffix string A suffix to display after the input box (e.g., suffix="$\rm m/s^2$").
weight integer 1 Weight to use when computing a weighted average score over elements.

Details

This element uses Pint to parse and represent units. Any units allowed by Pint are supported by this element. To obtain a Pint unit registry, question code can use pl.get_unit_registry() to construct a default unit registry. This is recommended over constructing a registry using the constructor provided by Pint (as this does not use caching and is slower).

Example implementations


Decorative Elements