Skip to content

Commit

Permalink
Moved exit survey function to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
okaycj committed Apr 3, 2024
1 parent 2bfc2d7 commit 1aa1f98
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
1 change: 0 additions & 1 deletion packages/lookit-initjspsych/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { initJsPsych as origInitJsPsych } from "jspsych";
import { JsPsychOptions } from "./types";
import { on_data_update, on_finish } from "./utils";


function lookitInitJsPsych(responseUuid: string) {
/**
* Function that returns a function to replace jsPsych's initJsPsych.
Expand Down
2 changes: 1 addition & 1 deletion packages/lookit-initjspsych/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export function on_finish(responseUuid: string, userFunc?: UserFunc) {
* in on_data_update. This will cause a reliable error,
*/
const { exit_url } = window.chs.study.attributes;

controller.abort("Writing final response data.");

await Api.updateResponse(responseUuid, {
Expand Down
16 changes: 1 addition & 15 deletions packages/surveys/src/exit.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ParameterType, TrialType } from "jspsych";
import { Model } from "survey-jquery";
import SurveyPlugin from "../../../../jsPsych/packages/plugin-survey/dist";
import surveyJSON from "./survey.json";
import { survey_function } from "./utils";
import { exit_survey_function } from "./utils";

const info = <const>{
...SurveyPlugin.info,
Expand Down Expand Up @@ -100,19 +99,6 @@ function surveyParameters(trial: Trial) {
return JSON.stringify(surveyJSON);
}

function exit_survey_function(survey: Model) {
survey_function(survey);
// For the withdrawal checkbox question, this takes the boolean response value out of an array
// and saves it as a single value (since there is always only one checkbox).
// We went with the checkbox question type rather than boolean with "renderAs: checkbox" because the
// latter doesn't allow both a question title and label next to the checkbox.
survey.onComplete.add(function (sender) {
const trueFalseValue =
sender.getQuestionByName("withdrawal").value.length > 0 ? true : false;
sender.setValue("withdrawal", trueFalseValue);
});
}

export class ExitSurveyPlugin extends SurveyPlugin {
static readonly info = info;
trial(display_element: HTMLElement, trial: Trial) {
Expand Down
13 changes: 13 additions & 0 deletions packages/surveys/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,16 @@ export function survey_function(survey: Model) {
});
return survey;
}

export function exit_survey_function(survey: Model) {
survey_function(survey);
// For the withdrawal checkbox question, this takes the boolean response value out of an array
// and saves it as a single value (since there is always only one checkbox).
// We went with the checkbox question type rather than boolean with "renderAs: checkbox" because the
// latter doesn't allow both a question title and label next to the checkbox.
survey.onComplete.add(function (sender) {
const trueFalseValue =
sender.getQuestionByName("withdrawal").value.length > 0;
sender.setValue("withdrawal", trueFalseValue);
});
}

0 comments on commit 1aa1f98

Please sign in to comment.