-
Hello everyone! I have a (hopefully easy to address) question related to one that has already been asked (#1146). There's a lot here, but most of it is included just to be thorough. Basically, I need to accept a form response and advance after a given I've so far been using I think the obvious solution is to modify the a) remove the button by simply commenting it out: // html += '<input type="submit" id="jspsych-survey-html-form-next" class="jspsych-btn jspsych-survey-html-form" value="'+trial.button_label+'"></input>'; and b) include a timeout function at the end of the if (trial.trial_duration !== null) {
jsPsych.pluginAPI.setTimeout(function() {
display_element.querySelector('#jspsych-survey-text-form-timed-NEW').requestSubmit();
}, trial.trial_duration);
} it is still not working. That is, everything (the Because I'm assuming this is an issue within plugin.trial = function(display_element, trial) {
var html = '';
// show preamble text
if(trial.preamble !== null){
html += '<div id="jspsych-survey-html-form-preamble" class="jspsych-survey-html-form-preamble">'+trial.preamble+'</div>';
}
// start form
if ( trial.autocomplete ) {
html += '<form id="jspsych-survey-html-form">'
} else {
html += '<form id="jspsych-survey-html-form" autocomplete="off">'
}
// add form HTML / input elements
html += trial.html;
// add submit button
// comment out button, although I tried keeping it in case it was needed for listening event below
// html += '<input type="submit" id="jspsych-survey-html-form-next" class="jspsych-btn jspsych-survey-html-form" value="'+trial.button_label+'"></input>';
html += '</form>';
display_element.innerHTML = html;
if ( trial.autofocus !== '' ) {
var focus_elements = display_element.querySelectorAll('#'+trial.autofocus);
if ( focus_elements.length === 0 ) {
console.warn('No element found with id: '+trial.autofocus);
} else if ( focus_elements.length > 1 ) {
console.warn('The id "'+trial.autofocus+'" is not unique so autofocus will not work.');
} else {
focus_elements[0].focus();
}
}
display_element.querySelector('#jspsych-survey-html-form-timed-NEW').addEventListener('submit', function(event) {
// don't submit form
event.preventDefault();
// measure response time
var endTime = performance.now();
var response_time = endTime - startTime;
var question_data = serializeArray(this);
if (!trial.dataAsArray) {
question_data = objectifyForm(question_data);
}
// save data
var trialdata = {
"rt": response_time,
"responses": JSON.stringify(question_data)
};
display_element.innerHTML = '';
// next trial
jsPsych.finishTrial(trialdata);
});
var startTime = performance.now();
// added by Garrett - this *should* simulate button event
// adapted from #1146
if (trial.trial_duration !== null) {
jsPsych.pluginAPI.setTimeout(function() {
display_element.querySelector('#jspsych-survey-text-form-timed-NEW').requestSubmit();
}, trial.trial_duration);
}
}; Again, this is mostly unchanged from the original I've tried leaving the button in (wouldn't actually work in an experiment, but thought some button object might need to exist), and it still won't auto-advance. I've also previously tried using a bare-bones plugin for this with a function adapted from Thank you for your time! Any advice would be appreciated! Best, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Update: I found a reasonable work-around. Instead of removing the button option and auto-advancing, I'm able to simply delay the activation of the button. This has the effect of keeping participants on a page for at least a given duration. Within the base button_duration: {
type: jsPsych.plugins.parameterType.INT,
pretty_name: 'Button activation delay',
default: null,
description: 'Delays button activation to ensure trial length. Button still needs pressing.'
} a chunk to classify button html, if (trial.button_duration !== null) {
html += '<input type="submit" id="jspsych-survey-html-delay-button-next" class="jspsych-btn jspsych-survey-html-delay-button" name="submit" value="'+trial.button_label+'" disabled></input>'
} else {
html += '<input type="submit" id="jspsych-survey-html-delay-button-next" class="jspsych-btn jspsych-survey-html-delay-button" name="submit" value="'+trial.button_label+'"></input>';
} and a timeout after the if (trial.button_duration !== null){
jsPsych.pluginAPI.setTimeout(function(){
display_element.querySelector('#jspsych-survey-html-delay-button-next').disabled = null;
}, trial.button_duration);
} Everything else is still identical to the base Best, |
Beta Was this translation helpful? Give feedback.
Update: I found a reasonable work-around. Instead of removing the button option and auto-advancing, I'm able to simply delay the activation of the button. This has the effect of keeping participants on a page for at least a given duration. Within the base
survey-html-form
, I simply added a new parameter,a chunk to classify button html,