ReferencechoiceInput

<choiceInput>

A multiple-choice input, allowing selection from a list of choices

<choiceInput> is an Input component that defines a block of code for multiple choice questions. It serves as a container element for the individual <choice> components that are nested within.

Attributes and Properties

Attributes for <choiceInput>

Labels (1)
labelIsName

boolean. Default value: false. Whether to use this component's name as its rendered label.

Other (10)

text. Two-way binding target for the input's value.

forAnswer

reference. References to <answer> elements that this input should submit to.

boolean. Default value: false. Whether to render the input inline (as a dropdown) rather than as a list of choices.

labelPosition

keyword. Position of the label relative to the input.

ValueDescription
start (default)Place the label before the input: to its left in a left-to-right document, to its right in a right-to-left one.
endPlace the label after the input: to its right in a left-to-right document, to its left in a right-to-left one.

boolean. Default value: false. Whether to award partial credit when only some correct choices are selected.

placeHolder

text. Placeholder text shown when no choice is selected.

number. Index of a choice to pre-select on initial render.

preserveLastChoice

boolean. Default value: false. Whether the last-rendered choice keeps its position when shuffling.

boolean. Default value: false. Whether multiple choices may be selected.

boolean. Default value: false. Whether to display the choices in randomized order.

Common to all components (9)
copy

reference. Create an independent copy of another component by reference. Enter a references a $name.

disabled

boolean. Default value: false. Whether this component is disabled and cannot be interacted with.

extend

reference. Extend another component by reference, inheriting its children and attributes. Enter a reference as $name.

fixed

boolean. Default value: false. Whether this component's value is fixed and cannot be modified.

fixLocation

boolean. Default value: false. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).

hide

boolean. Default value: false. Whether to hide this component from the rendered output.

isResponse

boolean. Default value: false. Whether this component is treated as a response for the purposes of assessment.

name

text. The name used to reference this component from elsewhere in the document.

styleNumber

integer. Default value: 1. The style number used to select this component's visual styling from the available style definitions.

Properties for <choiceInput name="c">

Labels (2)
$c.label

label. The label rendered with this component.

$c.labelIsName

boolean. Whether to use this component's name as its rendered label.

Other (24)

[ math ]. The math expressions of all choices in displayed order.

[ text ]. The text contents of all choices in displayed order.

$c.disabled

boolean. Whether this component is disabled and cannot be interacted with.

[ feedback ]. Feedback messages produced by selected choices.

$c.fixed

boolean. Whether this component's value is fixed and cannot be modified.

$c.fixLocation

boolean. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).

$c.focused

boolean. Whether this input currently has keyboard focus.

$c.hidden

boolean. Whether this component is hidden from the rendered output.

$c.inline

boolean. Whether the input is rendered inline (as a dropdown).

$c.labelPosition

text. Position of the label relative to the input.

$c.matchPartial

boolean. Whether to award partial credit when only some correct choices are selected.

number. The number of choices available in the input.

$c.numFeedbacks

number. The number of feedback messages produced by selected choices.

$c.preserveLastChoice

boolean. Whether the last-rendered choice keeps its position when shuffling.

$c.selectedIndex

number. The 1-based index of the first currently selected choice.

[ number ]. Indices (1-based) of the currently selected choices.

$c.selectedValue

The text value of the first currently selected choice.

Text values of the currently selected choices.

$c.selectMultiple

boolean. Whether multiple choices may be selected.

$c.shortDescription

text. A short accessibility description of this input; it is visible to screen readers but not rendered visually.

$c.shuffleOrder

boolean. Whether to display the choices in randomized order.

$c.valueChanged

boolean. Whether the input's selection has been changed from its initial state.

$c.values

The text values of the currently selected choices.

$c.valueToRecordOnSubmit

[ number ]. Indices of the currently selected choices (recorded when the answer is submitted).

Common to all components (4)
$c.doenetML

text. The DoenetML source code that produced this component.

$c.hide

boolean. Whether to hide this component from the rendered output.

$c.isResponse

boolean. Whether this component is treated as a response for the purposes of assessment.

$c.styleNumber

integer. The style number used to select this component's visual styling from the available style definitions.

Examples

Example: <choiceInput> for survey question

A <choiceInput> is used to collect user responses that do not require validation. A nested <label> child supplies the prompt for the choices.


Example: <choiceInput> in <answer>

A <choiceInput> can be nested within an <answer> to collect user responses with validation.


Example: <choiceInput> as a menu

A <choiceInput> can be used in combination with <conditionalContent> to create a simple menu.

Attribute Examples

Attribute Example: selectMultiple

The selectMultiple allows users to select multiple <choice> components in a <choiceInput>.


Attribute Example: matchPartial

If an <answer> requires more than one <choice> selection for full credit, the matchPartial attribute can be used to assign partial credit if one or more of the total number of correct choices are selected within a <choiceInput>.


Attribute Example: inline

The inline attribute provides a pull-down menu for <choice> selection rather than the default radio buttons.


Attribute Example: shuffleOrder

With the shuffleOrder attribute, the sequenceing of the choices is different for each page variant.


Attribute Example: preselectChoice

The preselectChoice attributes takes the index of the choice to preselect.


Attribute Example: bindValueTo

The <bindValueTo> takes a named component as input. The value of the <choiceInput> then becomes linked to that component’s value.

Property Examples

Property Example: numChoices

The numChoices property returns the number of nested <choice> children in the named <choiceInput>.


Property Example: choiceTexts

The choiceTexts property renders the texts contained in the <choiceInput> in an array.


Property Example: choiceMaths

The choiceMaths property renders the maths contained in the <choiceInput> in an array.


Property Example: selectedIndices

The selectedIndices property renders an array of the indices of all choices selected by the user.


Property Example: selectedValues

The selectedValues property renders an array of the values contained in all of the choices selected by the user.


Property Example: feedbacks

The feedbacks property should be copied in the document at the location where feedback should appear based on the specified interactions.