Adding a Color Picker/External Library to jsPsych #1435
-
I am trying to create a jsPsych plugin where the user can select a color for each stimulus. For this I am using jscolor. jscolor works well in vanilla HTML, but when I try to incorporate it in a jsPsych plugin it does not load the jscolor library. This is after I use
I don't understand why this exactly happens. Maybe I need to load the library inside the plugin somehoe? Adding display_element.innerHTML += '<script src="library/jscolor.js"></script>'; does not work either. How can I implement this in my plugin, or in my trials in general? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @umutreldem, One reason your plugin may not work right now is that the trial ends immediately after it begins because Another potential issue is that the jscolor library might expect the input to already be on the page when it loads. So you may need to tell jscolor that you've added a new input for it to modify. Based on a quick inspection of the docs, it looks like you'll need to call You'll likely want to move the |
Beta Was this translation helpful? Give feedback.
Hi @umutreldem,
One reason your plugin may not work right now is that the trial ends immediately after it begins because
jsPsych.finishTrial()
is called without waiting for any input from the user. I suspect if you comment out thejsPsych.finishTrial()
line then you'll see the jscolor input appear on the page.Another potential issue is that the jscolor library might expect the input to already be on the page when it loads. So you may need to tell jscolor that you've added a new input for it to modify. Based on a quick inspection of the docs, it looks like you'll need to call
jscolor.install()
(see here) after you modify the DOM.You'll likely want to move the
jsPsych.finishTrial()
call i…