Questionnaire
Description
An inline question with choice buttons that locks once answered
Questionnaire shows a question and a list of choice buttons. Once the user picks an answer, the component switches to a "response selected" mode that shows the question with the chosen answer highlighted and disables further input. Use it inline in a transcript, a form or a wizard, where a full ChoiceGroup would be too much and the answer is not meant to be changed afterwards.
SetAnswer puts the component into the answered state without invoking OnAnswered, which is how an already-known answer (one fetched from the server, say) is reflected on load. ClearAnswer re-enables the buttons. AddOption / AddOptions extend the choices after construction.
Samples
Asking and answering
Reflecting a known answer
API reference
public sealed class Questionnaire : ComponentBase<Questionnaire, HTMLElement>Inline questionnaire that shows a question and a list of choice buttons. Once the user picks an answer (or it is set programmatically via SetAnswer) the component switches to a "response selected" mode that shows the question with the chosen answer highlighted and disables further input.
- Namespace
- Tesserae
- Inheritance
- ComponentBase<Questionnaire, HTMLElement> → Questionnaire
Constructors
| Name | Description |
|---|---|
| Questionnaire | Initializes a new instance of this class. |
Properties
| Name | Description |
|---|---|
| Question | Gets the question shown by the component. |
| Answer | Gets the answer currently selected, or null when no answer has been set. |
| IsAnswered | Returns a value indicating whether the component is in the "response selected" mode. |
public string AnswerGets the answer currently selected, or null when no answer has been set.
Methods
| Name | Description |
|---|---|
| SetQuestion | Sets the question of the component. |
| AddOption | Adds the given option to the component. |
| AddOptions | Adds the given range of options to the component. |
| SetAnswer | Sets the selected answer and switches the component into the "response selected" mode. Calling this does not invoke the OnAnswered callback — use this to reflect an already-known answer (e.g. one fetched from the server). |
| ClearAnswer | Clears the selected answer and re-enables the option buttons. |
| OnAnswered | Registers a callback invoked when the user picks an option. The callback is not invoked when the answer is set programmatically via SetAnswer. |
| Render | Renders the component's root HTML element. |
public Questionnaire SetQuestion(string question)Sets the question of the component.
public Questionnaire AddOption(string option)Adds the given option to the component.
public Questionnaire AddOptions(IEnumerable<string> options)Adds the given range of options to the component.
public Questionnaire SetAnswer(string answer)Sets the selected answer and switches the component into the "response selected" mode. Calling this does not invoke the OnAnswered callback — use this to reflect an already-known answer (e.g. one fetched from the server).
public Questionnaire ClearAnswer()Clears the selected answer and re-enables the option buttons.
public Questionnaire OnAnswered(Action<Questionnaire> onAnswered)Registers a callback invoked when the user picks an option. The callback is not invoked when the answer is set programmatically via SetAnswer.
See also
- Choice Group — a radio group the user can keep changing.
- Rating — a star rating, when the answer is a score.
- Components overview