@jspsych/plugin-survey-multi-choice 1.1.3 → 2.0.1
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/dist/index.browser.js +217 -243
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.min.js +2 -2
- package/dist/index.browser.min.js.map +1 -1
- package/dist/index.cjs +216 -242
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +82 -34
- package/dist/index.js +216 -242
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/index.spec.ts +1 -1
- package/src/index.ts +42 -18
package/src/index.ts
CHANGED
|
@@ -1,72 +1,97 @@
|
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
|
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
|
|
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
|
-
/**
|
|
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.OBJECT,
|
|
84
|
+
},
|
|
85
|
+
/** 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. */
|
|
86
|
+
rt: {
|
|
87
|
+
type: ParameterType.INT,
|
|
88
|
+
},
|
|
89
|
+
/** 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. */
|
|
90
|
+
question_order: {
|
|
91
|
+
type: ParameterType.INT,
|
|
92
|
+
array: true,
|
|
93
|
+
},
|
|
94
|
+
},
|
|
70
95
|
};
|
|
71
96
|
|
|
72
97
|
type Info = typeof info;
|
|
@@ -74,10 +99,10 @@ type Info = typeof info;
|
|
|
74
99
|
/**
|
|
75
100
|
* **survey-multi-choice**
|
|
76
101
|
*
|
|
77
|
-
*
|
|
102
|
+
* The survey-multi-choice plugin displays a set of questions with multiple choice response fields. The participant selects a single answer.
|
|
78
103
|
*
|
|
79
104
|
* @author Shane Martin
|
|
80
|
-
* @see {@link https://www.jspsych.org/plugins/
|
|
105
|
+
* @see {@link https://www.jspsych.org/latest/plugins/survey-multi-choice/ survey-multi-choice plugin documentation on jspsych.org}
|
|
81
106
|
*/
|
|
82
107
|
class SurveyMultiChoicePlugin implements JsPsychPlugin<Info> {
|
|
83
108
|
static info = info;
|
|
@@ -226,7 +251,6 @@ class SurveyMultiChoicePlugin implements JsPsychPlugin<Info> {
|
|
|
226
251
|
response: question_data,
|
|
227
252
|
question_order: question_order,
|
|
228
253
|
};
|
|
229
|
-
display_element.innerHTML = "";
|
|
230
254
|
|
|
231
255
|
// next trial
|
|
232
256
|
this.jsPsych.finishTrial(trial_data);
|