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

View File

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