@jspsych/plugin-survey-multi-choice 1.1.3 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.ts CHANGED
@@ -1,72 +1,110 @@
1
1
  import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from "jspsych";
2
2
 
3
+ import { version } from "../package.json";
4
+
3
5
  const info = <const>{
4
6
  name: "survey-multi-choice",
7
+ version: version,
5
8
  parameters: {
6
- /** Array containing one or more objects with parameters for the question(s) that should be shown on the page. */
9
+ /**
10
+ * An array of objects, each object represents a question that appears on the screen. Each object contains a prompt,
11
+ * options, required, and horizontal parameter that will be applied to the question. See examples below for further
12
+ * clarification.`prompt`: Type string, default value is *undefined*. The string is prompt/question that will be
13
+ * associated with a group of options (radio buttons). All questions will get presented on the same page (trial).
14
+ * `options`: Type array, defualt value is *undefined*. An array of strings. The array contains a set of options to
15
+ * display for an individual question.`required`: Type boolean, default value is null. The boolean value indicates
16
+ * if a question is required('true') or not ('false'), using the HTML5 `required` attribute. If this parameter is
17
+ * undefined, the question will be optional. `horizontal`:Type boolean, default value is false. If true, then the
18
+ * question is centered and the options are displayed horizontally. `name`: Name of the question. Used for storing
19
+ * data. If left undefined then default names (`Q0`, `Q1`, `...`) will be used for the questions.
20
+ */
7
21
  questions: {
8
22
  type: ParameterType.COMPLEX,
9
23
  array: true,
10
- pretty_name: "Questions",
11
24
  nested: {
12
25
  /** Question prompt. */
13
26
  prompt: {
14
27
  type: ParameterType.HTML_STRING,
15
- pretty_name: "Prompt",
16
28
  default: undefined,
17
29
  },
18
30
  /** Array of multiple choice options for this question. */
19
31
  options: {
20
32
  type: ParameterType.STRING,
21
- pretty_name: "Options",
22
33
  array: true,
23
34
  default: undefined,
24
35
  },
25
36
  /** Whether or not a response to this question must be given in order to continue. */
26
37
  required: {
27
38
  type: ParameterType.BOOL,
28
- pretty_name: "Required",
29
39
  default: false,
30
40
  },
31
41
  /** If true, then the question will be centered and options will be displayed horizontally. */
32
42
  horizontal: {
33
43
  type: ParameterType.BOOL,
34
- pretty_name: "Horizontal",
35
44
  default: false,
36
45
  },
37
46
  /** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */
38
47
  name: {
39
48
  type: ParameterType.STRING,
40
- pretty_name: "Question Name",
41
49
  default: "",
42
50
  },
43
51
  },
44
52
  },
45
- /** If true, the order of the questions in the 'questions' array will be randomized. */
53
+ /**
54
+ * If true, the display order of `questions` is randomly determined at the start of the trial. In the data object,
55
+ * `Q0` will still refer to the first question in the array, regardless of where it was presented visually.
56
+ */
46
57
  randomize_question_order: {
47
58
  type: ParameterType.BOOL,
48
- pretty_name: "Randomize Question Order",
49
59
  default: false,
50
60
  },
51
- /** HTML-formatted string to display at top of the page above all of the questions. */
61
+ /** HTML formatted string to display at the top of the page above all the questions. */
52
62
  preamble: {
53
63
  type: ParameterType.HTML_STRING,
54
- pretty_name: "Preamble",
55
64
  default: null,
56
65
  },
57
- /** Label of the button to submit responses. */
66
+ /** Label of the button. */
58
67
  button_label: {
59
68
  type: ParameterType.STRING,
60
- pretty_name: "Button label",
61
69
  default: "Continue",
62
70
  },
63
- /** Setting this to true will enable browser auto-complete or auto-fill for the form. */
71
+ /**
72
+ * This determines whether or not all of the input elements on the page should allow autocomplete. Setting
73
+ * this to true will enable autocomplete or auto-fill for the form.
74
+ */
64
75
  autocomplete: {
65
76
  type: ParameterType.BOOL,
66
- pretty_name: "Allow autocomplete",
67
77
  default: false,
68
78
  },
69
79
  },
80
+ data: {
81
+ /** An object containing the response for each question. The object will have a separate key (variable) for each question, with the first question in the trial being recorded in `Q0`, the second in `Q1`, and so on. The responses are recorded as integers, representing the position selected on the likert scale for that question. If the `name` parameter is defined for the question, then the response object will use the value of `name` as the key for each question. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */
82
+ response: {
83
+ type: ParameterType.COMPLEX,
84
+ nested: {
85
+ identifier: {
86
+ type: ParameterType.STRING,
87
+ },
88
+ response: {
89
+ type:
90
+ ParameterType.STRING |
91
+ ParameterType.INT |
92
+ ParameterType.FLOAT |
93
+ ParameterType.BOOL |
94
+ ParameterType.OBJECT,
95
+ },
96
+ },
97
+ },
98
+ /** The response time in milliseconds for the participant to make a response. The time is measured from when the questions first appear on the screen until the participant's response(s) are submitted. */
99
+ rt: {
100
+ type: ParameterType.INT,
101
+ },
102
+ /** An array with the order of questions. For example `[2,0,1]` would indicate that the first question was `trial.questions[2]` (the third item in the `questions` parameter), the second question was `trial.questions[0]`, and the final question was `trial.questions[1]`. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */
103
+ question_order: {
104
+ type: ParameterType.INT,
105
+ array: true,
106
+ },
107
+ },
70
108
  };
71
109
 
72
110
  type Info = typeof info;
@@ -74,10 +112,10 @@ type Info = typeof info;
74
112
  /**
75
113
  * **survey-multi-choice**
76
114
  *
77
- * jsPsych plugin for presenting multiple choice survey questions
115
+ * The survey-multi-choice plugin displays a set of questions with multiple choice response fields. The participant selects a single answer.
78
116
  *
79
117
  * @author Shane Martin
80
- * @see {@link https://www.jspsych.org/plugins/jspsych-survey-multi-choice/ survey-multi-choice plugin documentation on jspsych.org}
118
+ * @see {@link https://www.jspsych.org/latest/plugins/survey-multi-choice/ survey-multi-choice plugin documentation on jspsych.org}
81
119
  */
82
120
  class SurveyMultiChoicePlugin implements JsPsychPlugin<Info> {
83
121
  static info = info;
@@ -226,7 +264,6 @@ class SurveyMultiChoicePlugin implements JsPsychPlugin<Info> {
226
264
  response: question_data,
227
265
  question_order: question_order,
228
266
  };
229
- display_element.innerHTML = "";
230
267
 
231
268
  // next trial
232
269
  this.jsPsych.finishTrial(trial_data);