next button rework

This commit is contained in:
Xiaolu Bai 2017-01-13 13:30:20 -08:00
parent 467dcb0460
commit 5cb6b31943
2 changed files with 38 additions and 42 deletions

View File

@ -84,24 +84,22 @@ jsPsych.plugins.instructions = (function() {
if (trial.show_clickable_nav) { if (trial.show_clickable_nav) {
var nav_html = "<div class='jspsych-instructions-nav'>"; var nav_html = "<div class='jspsych-instructions-nav'>";
if (current_page != 0 && trial.allow_backward) { // if (current_page != 0 && trial.allow_backward) {
nav_html += "<button id='jspsych-instructions-back' class='jspsych-btn'>&lt; Previous</button>"; // nav_html += "<button id='jspsych-instructions-back' class='jspsych-btn'>&lt; Previous</button>";
} // }
nav_html += "<button id='jspsych-instructions-next' class='jspsych-btn'>Next &gt;</button></div>" // nav_html += "<button id='jspsych-instructions-next' class='jspsych-btn'>Next &gt;</button></div>"
display_element.innerHTML += nav_html; display_element.innerHTML += nav_html;
if (current_page != 0 && trial.allow_backward) { // if (current_page != 0 && trial.allow_backward) {
display_element.querySelector('#jspsych-instructions-back').attachEventListener('click', function() { // display_element.querySelector('#jspsych-instructions-back').addEventListener('click', function() {
clear_button_handlers(); // clear_button_handlers();
back(); // });
}); // }
} //
// display_element.querySelector('#jspsych-instructions-next').addEventListener('click', function() {
display_element.querySelector('#jspsych-instructions-next').attachEventListener('click', function() { // clear_button_handlers();
clear_button_handlers(); // });
next();
});
} }
} }
@ -111,29 +109,29 @@ jsPsych.plugins.instructions = (function() {
display_element.querySelector('#jspsych-instructions-back').removeEventListener('click'); display_element.querySelector('#jspsych-instructions-back').removeEventListener('click');
} }
function next() { // function next() {
//
add_current_page_to_view_history() // add_current_page_to_view_history()
//
current_page++; // current_page++;
//
// if done, finish up... // // if done, finish up...
if (current_page >= trial.pages.length) { // if (current_page >= trial.pages.length) {
endTrial(); // endTrial();
} else { // } else {
show_current_page(); // show_current_page();
} // }
//
} // }
//
function back() { // function back() {
//
add_current_page_to_view_history() // add_current_page_to_view_history()
//
current_page--; // current_page--;
//
show_current_page(); // show_current_page();
} // }
function add_current_page_to_view_history() { function add_current_page_to_view_history() {

View File

@ -133,7 +133,7 @@ jsPsych.plugins['survey-multi-choice'] = (function() {
} }
} }
// add submit button // add submit button
trial_form.innerHTML += '<input type="submit" id="'+plugin_id_name+'-next" class="'+plugin_id_name+' jspsych-btn">Submit Answers</input>'; trial_form.innerHTML += '<input type="submit" id="'+plugin_id_name+'-next" class="'+plugin_id_name+' jspsych-btn"> next </input>';
trial_form.addEventListener('submit', function(event) { trial_form.addEventListener('submit', function(event) {
event.preventDefault(); event.preventDefault();
@ -145,17 +145,15 @@ jsPsych.plugins['survey-multi-choice'] = (function() {
// create object to hold responses // create object to hold responses
var question_data = {}; var question_data = {};
//TODO this is having problems
var matches = display_element.querySelectorAll("div." + plugin_id_name + "-question"); var matches = display_element.querySelectorAll("div." + plugin_id_name + "-question");
var inputs = document.getElementsByTagName('input'); var inputs = document.getElementsByTagName('input');
var radios = [] var radios = []
for(var i=0;i<inputs.length;i++){ for(var i = 0; i < inputs.length; i++){
if(inputs[i].checked){ if(inputs[i].checked){
radios.push(inputs[i].value) radios.push(inputs[i].value)
} }
} }
matches.forEach(function(currentEl ,index){ matches.forEach(function(currentEl ,index){
console.log("currentEl", currentEl,index)
var id = "Q" + index; var id = "Q" + index;
var obje = {}; var obje = {};
obje[id] = radios[index]; obje[id] = radios[index];