jsPsych icon indicating copy to clipboard operation
jsPsych copied to clipboard

breaking survey 2.0.0 plugin: `title` cannot be a function

Open DominiqueMakowski opened this issue 1 year ago • 6 comments

It seems like version 2.0.0 doesn't allow for the title field to be dynamically set via a function anymore

var rating = {
    type: jsPsychSurvey,
    survey_json: {
        title: "MY TITLE",
        // title: function () {
        //     return "MY TITLE"
        // },
        description: "Some description",
        pages: [
            {
                elements: [
                    {
                        type: "rating",
                        name: "Something",
                        title: "My question",
                        rateMin: 0,
                        rateMax: 6,
                    },
                ],
            },
        ],
    },
}

It just doesn't show any title or description when title is a function.

DominiqueMakowski avatar Jul 20 '24 09:07 DominiqueMakowski

Actually, reversing survey only to 1.0.1 didn't fix it, I had to revert the whole JsPsych to v7 It's probably an upstream issue

DominiqueMakowski avatar Jul 20 '24 09:07 DominiqueMakowski

Hi @DominiqueMakowski,

In version 8 the process for checking plugin parameters and converting functions to values is more strict, and this does indeed break the survey plugin. The workaround would be to make the entire survey_json a function, and just dynamically set the title in that.

@bjoluc what do you think about some kind of parameter or flag that would tell the core library to recursively check an object, without manually specifying all allowable values?

jodeleeuw avatar Jul 20 '24 13:07 jodeleeuw

After trying to adapt to the new system, I must admit it's quite cumbersome, especially for long surveys spanning multiple pages where it would be much more straightforward to have each element dynamically set rather than having to code a megafunction to set the whole survey dynamically.

Is there any potential avenue for relaxing some of the restrictions in this survey to make it more user-friendly?

DominiqueMakowski avatar Aug 23 '24 17:08 DominiqueMakowski

Thanks for bumping, @DominiqueMakowski! @jspsych/core What do you think about baking this into the survey plugin and releasing it in a patch version? I don't think the pattern is common enough to support it in the core library (?) and joining multiple distinct parameters into one "complex" parameter has the slight smell of an anti-pattern IMO. Nevertheless, in this situation it makes perfect sense, so I think it should be handled by the survey plugin itself.

bjoluc avatar Aug 23 '24 18:08 bjoluc

I'm on board with that 👍

jodeleeuw avatar Aug 23 '24 19:08 jodeleeuw

Yes! I agree it's too unusual to be flagged and handled by the core library. In most cases the 'jsPsych approach' would be to break the JSON out into separate parameters, but here we're intentionally not doing that to remain compatible with SurveyJS. I don't know why I hadn't thought of just adding this functionality into the plugin itself 🤦‍♀️ I'd be happy to do this.

becky-gilbert avatar Aug 26 '24 18:08 becky-gilbert