Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Abort study button not working on the server deployment?

Hello there

I am using JATOS with jsPsych, and have an addAbortButton() in the on_trial_start area of jsPsych.init(). It works perfectly fine in JATOS local 3.5.8, but it fails to work in JATOS server 3.5.4. The documentation says it is compatible with 3.5.1 onward, so it should technically work? Any leads on how to get it working?

Comments

  • krikri
    edited March 2021

    Hi!

    I compared the old version (3.5.1) with the current one (3.5.9): The main difference is that in the old version jatos.addAbortButton waits with adding the button until the 'load' event is fired, while the current version just add the button right away. This might be the problem in your study. If in your study the 'load' event is fired earlier then the execution of jatos.addAbortButton then the button won't be add at all.

    One solution is to call jatos.addAbortButton as early as possible, right at the beginning of your JavaScript.

    And if this doesn't work just implement your own version of jatos.addAbortButton. Just put this code somewhere in your code and call it. This is the same code as the current jatos.js is using just with addAbortButton instead of jatos.addAbortButton - that means you call it with addAbortButton();.

    var addAbortButton = function (config) {
       var buttonText = (config && typeof config.text == "string") ?
             config.text : "Cancel";
       var confirm = (config && typeof config.confirm == "boolean") ?
             config.confirm : true;
       var confirmText = (config && typeof config.confirmText == "string") ?
             config.confirmText : "Do you really want to cancel this study?";
       var tooltip = (config && typeof config.tooltip == "string") ?
             config.tooltip : "Cancels this study and deletes all already submitted data";
       var msg = (config && typeof config.msg == "string") ?
             config.msg : "Worker decided to abort";
       var style = 'color:black;' +
             'font-family:Sans-Serif;' +
             'font-size:20px;' +
             'letter-spacing:2px;' +
             'position:fixed;' +
             'margin:2em 0 0 2em;' +
             'bottom:1em;' +
             'right:1em;' +
             'opacity:0.6;' +
             'z-index:100;' +
             'cursor:pointer;' +
             'text-shadow:-1px 0 white, 0 1px white, 1px 0 white, 0 -1px white;';
       if (config && typeof config.style == "string") style += ";" + config.style;
    
       var text = document.createTextNode(buttonText);
       var buttonDiv = document.createElement('div');
       buttonDiv.appendChild(text);
       buttonDiv.style.cssText = style;
       buttonDiv.setAttribute("title", tooltip);
       buttonDiv.addEventListener("click", function () {
          if (!confirm || window.confirm(confirmText)) {
             jatos.abortStudy(msg);
          }
       });
    
       document.body.appendChild(buttonDiv);
    };
    

    Best,

    Kristian

Sign In or Register to comment.