change from check_blanks to allow_blanks

This commit is contained in:
jadeddelta 2022-09-23 15:51:39 -04:00
parent 2f1a867494
commit 68c3490f91
6 changed files with 19 additions and 19 deletions

View File

@ -2,4 +2,4 @@
"@jspsych/plugin-cloze": minor "@jspsych/plugin-cloze": minor
--- ---
added `check_blanks` as a field, allowing for completion checking of answers added `allow_blanks` as a field, allowing for completion checking of answers

View File

@ -16,7 +16,7 @@
var trial = { var trial = {
type: jsPsychCloze, type: jsPsychCloze,
text: 'Science notebooks have a %%-colored front cover. Math notebooks have a %%-colored front cover.', text: 'Science notebooks have a %%-colored front cover. Math notebooks have a %%-colored front cover.',
check_blanks: true, allow_blanks: false,
mistake_fn: function() { alert('Please fill in all blanks.'); } mistake_fn: function() { alert('Please fill in all blanks.'); }
}; };

View File

@ -2,7 +2,7 @@
Current version: 1.1.1. [See version history](https://github.com/jspsych/jsPsych/blob/main/packages/plugin-cloze/CHANGELOG.md). Current version: 1.1.1. [See version history](https://github.com/jspsych/jsPsych/blob/main/packages/plugin-cloze/CHANGELOG.md).
This plugin displays a text with certain words removed. Participants are asked to replace the missing items. Responses are recorded when clicking a button. Optionally, responses are evaluated and a function is called in case of differences, making it possible to inform participants about mistakes. This plugin displays a text with certain words removed. Participants are asked to replace the missing items. Responses are recorded when clicking a button. Responses can be evaluated and a function is called in case of either differences or incomplete answers, making it possible to inform participants about mistakes before proceeding.
## Parameters ## Parameters
@ -13,8 +13,8 @@ In addition to the [parameters available in all plugins](../overview/plugins.md#
| text | string | *undefined* | The cloze text to be displayed. Blanks are indicated by %% signs and automatically replaced by input fields. If there is a correct answer you want the system to check against, it must be typed between the two percentage signs (i.e. % correct solution %). | | text | string | *undefined* | The cloze text to be displayed. Blanks are indicated by %% signs and automatically replaced by input fields. If there is a correct answer you want the system to check against, it must be typed between the two percentage signs (i.e. % correct solution %). |
| button_text | string | OK | Text of the button participants have to press for finishing the cloze test. | | button_text | string | OK | Text of the button participants have to press for finishing the cloze test. |
| check_answers | boolean | false | Boolean value indicating if the answers given by participants should be compared against a correct solution given in the text (between % signs) after the button was clicked. If ```true```, answers are checked and in case of differences, the ```mistake_fn``` is called. In this case, the trial does not automatically finish. If ```false```, no checks are performed and the trial automatically ends when clicking the button. | | check_answers | boolean | false | Boolean value indicating if the answers given by participants should be compared against a correct solution given in the text (between % signs) after the button was clicked. If ```true```, answers are checked and in case of differences, the ```mistake_fn``` is called. In this case, the trial does not automatically finish. If ```false```, no checks are performed and the trial automatically ends when clicking the button. |
| check_blanks | boolean | false | Boolean value indicating if the answers given by participants should be checked for completion after the button was clicked. If ```true```, answers are checked and in case there are some missing, the ```mistake_fn``` is called. In this case, the trial does not automatically finish. If ```false```, no checks are performed and the trial automatically ends when clicking the button. | | allow_blanks | boolean | true | Boolean value indicating if the answers given by participants should be checked for completion after the button was clicked. If ```true```, answers are not checked for completion and blank answers are allowed. The trial will then automatically finish upon the clicking the button. If ```false```, answers are checked for completion, and in case there are some fields with missing answers, the ```mistake_fn``` is called. In this case, the trial does not automatically finish. |
| mistake_fn | function | ```function(){}``` | Function called if ```check_answers``` is set to ```true``` and there is a difference between the participants answers and the correct solution provided in the text. | | mistake_fn | function | ```function(){}``` | Function called if ```check_answers``` is set to ```true``` or ```allow_blanks``` is set to false and there is a difference between the participants answers and the correct solution provided in the text, or if there is at least one field with a blank answer respectively. |
## Data Generated ## Data Generated
@ -70,7 +70,7 @@ import cloze from '@jspsych/plugin-cloze';
var cloze_trial = { var cloze_trial = {
type: jsPsychCloze, type: jsPsychCloze,
text: 'Science notebooks have a %%-colored front cover. Math notebooks have a %%-colored front cover.', text: 'Science notebooks have a %%-colored front cover. Math notebooks have a %%-colored front cover.',
check_blanks: true, allow_blanks: false,
mistake_fn: function() { alert('Please fill in all blanks.'); } mistake_fn: function() { alert('Please fill in all blanks.'); }
}; };
``` ```

View File

@ -26,7 +26,7 @@
timeline.push({ timeline.push({
type: jsPsychCloze, type: jsPsychCloze,
text: 'Science notebooks have a %%-colored front cover. Math notebooks have a %%-colored front cover.', text: 'Science notebooks have a %%-colored front cover. Math notebooks have a %%-colored front cover.',
check_blanks: true, allow_blanks: false,
mistake_fn: function () { alert("You have not filled in all the blanks!"); } mistake_fn: function () { alert("You have not filled in all the blanks!"); }
}); });

View File

@ -78,7 +78,7 @@ describe("cloze", () => {
{ {
type: cloze, type: cloze,
text: "This is a %cloze% text.", text: "This is a %cloze% text.",
check_blanks: true, allow_blanks: false,
}, },
]); ]);
@ -106,7 +106,7 @@ describe("cloze", () => {
{ {
type: cloze, type: cloze,
text: "This is a %cloze% text.", text: "This is a %cloze% text.",
check_answers: true, allow_blanks: false,
}, },
]); ]);
@ -139,7 +139,7 @@ describe("cloze", () => {
{ {
type: cloze, type: cloze,
text: "This is a %cloze% text.", text: "This is a %cloze% text.",
check_blanks: true, allow_blanks: false,
mistake_fn: mistakeFn, mistake_fn: mistakeFn,
}, },
]); ]);

View File

@ -21,13 +21,13 @@ const info = <const>{
pretty_name: "Check answers", pretty_name: "Check answers",
default: false, default: false,
}, },
/** Boolean value indicating if the answers given by participants should be checked for completeness after the button is clicked in order to move on. */ /** Boolean value indicating if the answers given by participants */
check_blanks: { allow_blanks: {
type: ParameterType.BOOL, type: ParameterType.BOOL,
pretty_name: "Check blanks", pretty_name: "Check blanks",
default: false, default: true,
}, },
/** Function called if either the check_answers or check_blanks is set to TRUE and there is a discrepancy between the set answers and the answers provide or if all blanks aren't filled out, respectively. */ /** Function called if either the check_answers is set to TRUE or the allow_blanks is set to FALSE and there is a discrepancy between the set answers and the answers provide or if all blanks aren't filled out, respectively. */
mistake_fn: { mistake_fn: {
type: ParameterType.FUNCTION, type: ParameterType.FUNCTION,
pretty_name: "Mistake function", pretty_name: "Mistake function",
@ -88,14 +88,14 @@ class ClozePlugin implements JsPsychPlugin<Info> {
field.style.color = "black"; field.style.color = "black";
} }
} }
if (trial.check_blanks) { if (!trial.allow_blanks) {
if (answers[i] === "") { if (answers[i] === "") {
answers_filled = false; answers_filled = false;
} }
} }
} }
if ((trial.check_answers && !answers_correct)||(trial.check_blanks && !answers_filled)) { if ((trial.check_answers && !answers_correct) || (!trial.allow_blanks && !answers_filled)) {
trial.mistake_fn(); trial.mistake_fn();
} else { } else {
var trial_data = { var trial_data = {