Merge pull request #362 from hugueslacroix/master

New parameters for survey-text and survey-likert
This commit is contained in:
Josh de Leeuw 2017-03-30 09:37:29 -04:00 committed by GitHub
commit 04a118682e
2 changed files with 12 additions and 3 deletions

View File

@ -38,6 +38,7 @@ jsPsych.plugins['survey-likert'] = (function() {
// default parameters for the trial // default parameters for the trial
trial.preamble = typeof trial.preamble === 'undefined' ? "" : trial.preamble; trial.preamble = typeof trial.preamble === 'undefined' ? "" : trial.preamble;
trial.required = typeof trial.required === 'undefined' ? false : trial.required; trial.required = typeof trial.required === 'undefined' ? false : trial.required;
trial.button_label = typeof trial.button_label === 'undefined' ? 'Submit Answers' : trial.button_label;
// if any trial variables are functions // if any trial variables are functions
// this evaluates the function and replaces // this evaluates the function and replaces
@ -80,7 +81,7 @@ jsPsych.plugins['survey-likert'] = (function() {
} }
// add submit button // add submit button
form_element.innerHTML += '<input type="submit" id="jspsych-survey-likert-next" class="jspsych-survey-likert jspsych-btn" value="Submit Answers"></input>'; form_element.innerHTML += '<input type="submit" id="jspsych-survey-likert-next" class="jspsych-survey-likert jspsych-btn" value="'+trial.button_label+'"></input>';
form_element.addEventListener('submit', function(e){ form_element.addEventListener('submit', function(e){
e.preventDefault(); e.preventDefault();

View File

@ -50,6 +50,8 @@ jsPsych.plugins['survey-text'] = (function() {
plugin.trial = function(display_element, trial) { plugin.trial = function(display_element, trial) {
trial.preamble = typeof trial.preamble == 'undefined' ? "" : trial.preamble; trial.preamble = typeof trial.preamble == 'undefined' ? "" : trial.preamble;
trial.button_label = typeof trial.button_label === 'undefined' ? 'Submit Answers' : trial.button_label;
if (typeof trial.rows == 'undefined') { if (typeof trial.rows == 'undefined') {
trial.rows = []; trial.rows = [];
for (var i = 0; i < trial.questions.length; i++) { for (var i = 0; i < trial.questions.length; i++) {
@ -62,6 +64,12 @@ jsPsych.plugins['survey-text'] = (function() {
trial.columns.push(40); trial.columns.push(40);
} }
} }
if (typeof trial.values == 'undefined') {
trial.values = [];
for (var i = 0; i < trial.questions.length; i++) {
trial.values.push("");
}
}
// if any trial variables are functions // if any trial variables are functions
// this evaluates the function and replaces // this evaluates the function and replaces
@ -75,12 +83,12 @@ jsPsych.plugins['survey-text'] = (function() {
for (var i = 0; i < trial.questions.length; i++) { for (var i = 0; i < trial.questions.length; i++) {
display_element.innerHTML += '<div id="jspsych-survey-text-"'+i+'" class="jspsych-survey-text-question" style="margin: 2em 0em;">'+ display_element.innerHTML += '<div id="jspsych-survey-text-"'+i+'" class="jspsych-survey-text-question" style="margin: 2em 0em;">'+
'<p class="jspsych-survey-text">' + trial.questions[i] + '</p>'+ '<p class="jspsych-survey-text">' + trial.questions[i] + '</p>'+
'<textarea name="#jspsych-survey-text-response-' + i + '" cols="' + trial.columns[i] + '" rows="' + trial.rows[i] + '"></textarea>'+ '<textarea name="#jspsych-survey-text-response-' + i + '" cols="' + trial.columns[i] + '" rows="' + trial.rows[i] + '">'+trial.values[i]+'</textarea>'+
'</div>'; '</div>';
} }
// add submit button // add submit button
display_element.innerHTML += '<button id="jspsych-survey-text-next" class="jspsych-btn jspsych-survey-text">Submit Answers</button>'; display_element.innerHTML += '<button id="jspsych-survey-text-next" class="jspsych-btn jspsych-survey-text">'+trial.button_label+'</button>';
display_element.querySelector('#jspsych-survey-text-next').addEventListener('click', function() { display_element.querySelector('#jspsych-survey-text-next').addEventListener('click', function() {
// measure response time // measure response time