<textInput/>
<textInput/> is an Input
component that renders a form input field for text responses from the user.
Attributes and Properties
Attributes for <textInput>
Labels (1)
boolean. Default value: false. Whether to use this component's name as its rendered label.
Positioning (2)
anchorpoint. Default value: . Coordinates of the anchor point used to position this component on a graph.
positionFromAnchorkeyword. Where this component sits relative to its anchor point.
| Value | Description |
|---|---|
upperRightAdded in 0.7.10 | Place the component above and to the right of the anchor point. |
upperLeftAdded in 0.7.10 | Place the component above and to the left of the anchor point. |
lowerRightAdded in 0.7.10 | Place the component below and to the right of the anchor point. |
lowerLeftAdded in 0.7.10 | Place the component below and to the left of the anchor point. |
top | Place the component directly above the anchor point. |
bottom | Place the component directly below the anchor point. |
left | Place the component directly to the left of the anchor point. |
right | Place the component directly to the right of the anchor point. |
center (default) | Center the component on the anchor point. |
Other (8)
bindValueTotext. Two-way binding target for the input's value.
boolean. Default value: true. Whether the input can be dragged on a graph.
boolean. Default value: false. Whether the input renders as a multi-line text area.
forAnswerAdded in 0.7.4reference. References to <answer> elements that this input should submit to.
componentSize. Default value: 120px. Display height of the input. Applies only to an expanded input.
labelPositionAdded in 0.7.10keyword. Position of the label relative to the input.
| Value | Description |
|---|---|
start (default)Added in 0.7.22 | Place the label before the input: to its left in a left-to-right document, to its right in a right-to-left one. |
endAdded in 0.7.22 | Place the label after the input: to its right in a left-to-right document, to its left in a right-to-left one. |
text. Initial text shown in the input before the user types.
componentSize. Display width of the input. Defaults to 100% when expanded, and to 100px otherwise.
Common to all components (9)
copyreference. Create an independent copy of another component by reference. Enter a references a $name.
disabledboolean. Default value: false. Whether this component is disabled and cannot be interacted with.
extendreference. Extend another component by reference, inheriting its children and attributes. Enter a reference as $name.
fixedboolean. Default value: false. Whether this component's value is fixed and cannot be modified.
fixLocationboolean. Default value: false. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).
hideboolean. Default value: false. Whether to hide this component from the rendered output.
isResponseboolean. Default value: false. Whether this component is treated as a response for the purposes of assessment.
nametext. The name used to reference this component from elsewhere in the document.
styleNumberinteger. Default value: 1. The style number used to select this component's visual styling from the available style definitions.
Properties for <textInput name="t">
Labels (2)
$t.labellabel. The label rendered with this component.
$t.labelIsNameboolean. Whether to use this component's name as its rendered label.
Positioning (2)
$t.anchorpoint. The coordinates where this component is anchored on the graph.
$t.positionFromAnchortext. Where this component sits relative to its anchor point.
Other (19)
$t.characters[ text ]. The text value split into characters (graphemes).
$t.draggableboolean. Whether the input can be dragged on a graph.
$t.expandedboolean. Whether the input renders as a multi-line text area.
$t.focusedAdded in 0.7.10boolean. Whether this input currently has keyboard focus.
$t.heightcomponentSize. Display height of the input. Applies only to an expanded input.
text. The text value reflecting the user's in-progress edits.
$t.immediateValueChangedboolean. Whether the value, including in-progress edits, has been changed from its initial state.
$t.labelPositionAdded in 0.7.10text. Position of the label relative to the input.
$t.list[ text ]. The text value split into items at commas.
$t.numCharactersinteger. The number of characters (graphemes) in the text value.
$t.numListItemsinteger. The number of comma-separated items when the text is interpreted as a list.
$t.numWordsinteger. The number of words in the text value.
$t.prefilltext. Initial text shown in the input before the user types.
$t.shortDescriptiontext. A short accessibility description of this input; it is visible to screen readers but not rendered visually.
$t.texttext. The current text as a plain text string.
$t.valuetext. The text value of the input.
$t.valueChangedboolean. Whether the value has been changed from its initial state.
$t.widthcomponentSize. Display width of the input. Defaults to 100% when expanded, and to 100px otherwise.
$t.words[ text ]. The text value split into words.
Common to all components (8)
$t.disabledboolean. Whether this component is disabled and cannot be interacted with.
$t.doenetMLtext. The DoenetML source code that produced this component.
$t.fixedboolean. Whether this component's value is fixed and cannot be modified.
$t.fixLocationboolean. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).
$t.hideboolean. Whether to hide this component from the rendered output.
$t.isResponseboolean. Whether this component is treated as a response for the purposes of assessment.
$t.styleNumberinteger. The style number used to select this component's visual styling from the available style definitions.
Examples
Example: Default <textInput/>
The default <textInput/> blank is wide enough for approximately 2-4 words to be visible at a time.
Example: Large <textInput/>
The expanded <textInput/> blank spans the width available to it and is
approximately tall enough for 4-6 sentences to be visible at a time.
Example: <textInput/> with <label> child
The <textInput/> component can take a nested <label> child.
Example: <textInput/> for graded free-response
The <textInput/> can be nested in an <answer> with the handGraded attribute for graded free-response style questions.
Example: <textInput/> for graded closed-form text response
The <textInput/> can be nested in an <answer> that checks the entered text against an expected value, automatically grading a closed-form text response.
Example: <textInput/> on a <graph>
A <textInput/> can be placed on a <graph>. Use the anchor attribute to adjust its starting location. Click on the border of the <textInput/> to drag it around.
Attribute Examples
Attribute Example: prefill
The prefill attribute specifies initial text for the <textInput/>.
Attribute Example: expanded
The expanded attribute renders a larger <textInput/> space. An expanded
input fills the width available to it, and is 120 pixels tall. Both dimensions
can be customized with the width and height attributes.
Attribute Example: forAnswer
Specifying the attribute forAnswer of a <textInput> does two things:
- It colors the border of the text input based on the correctness of the response (assuming
colorCorrectnessis not set tofalse). - It includes the value of the text input as a response of the answer.
Attribute Example: width
The default width of the input space can be customized with the width attribute.
A bare number is a number of pixels, and physical units such as 6in or 15cm
are read as well — see Sizes for the full
list of forms a size may take.
Attribute Example: width as a percentage
An expanded <textInput/> may be given its width as a percentage of the
width available to it, so that it stays in proportion when the reader’s window
is narrow. That is also its default: an expanded input with no width of its
own is 100% wide. An expanded input never grows wider than the column it sits
in, even when it asks for more.
A word-sized (not expanded) input is the exception: it keeps whatever width
it is given — 100 pixels by default — and the line it sits in closes around it,
so a percentage there would be a share of a box whose own width depends on the
input. Give a word-sized input an absolute width.
Attribute Example: height
The default height of the input space can be customized with the height attribute. This must be used in combination with the expanded attribute.
A bare number is a number of pixels, and physical units such as 6in or 15cm
are read as well. See Sizes.
Attribute Example: labelIsName
The labelIsName attribute can be used to assign an automatic label to a <textInput/>.
Attribute Example: draggable
The draggable attribute can be set to false to prevent users from moving the <textInput/> on a <graph>.
Property Examples
Property Example: value
The value property contains the finalized value the user entered into the input. It is updated when the user presses enter or navigates away.
Property Example: immediateValue
The immediateValue property contains the value the user enters into the input as they are typing.
Property Example: attributes as properties
The attributes illustrated in the example are also accessible as properties. The value stored in a <label> child can also be rendered using the label property.