Solved
Disable Next Button until embedded data field condition is met
I have a task where participants are asked to move two chairs and the computer records the location of the chairs. I want to be sure that participants move the chairs before being able to click on the next button.
One way I was thinking to do this is to disable the next button until the condition of moving the chair is met. The computer records the movement of the chairs with pixels using embedded data. If participants do not move the chairs the values for the embedded data fields "you x" and "you y" are left blank. Is there a way to write java code so that the next button will appear only if the chair is moved (if embedded data field is not blank)? I am not a programmer so am not sure what to do.
Here is a link to my task: https://qaz1.az1.qualtrics.com/jfe/form/SV_9Griq4aYcfbUBWl
Here is the embedded data code:

{
/*Place your JavaScript here to run when the page loads*/
});
Qualtrics.SurveyEngine.addOnReady(function() {
//variables
var draggableClassName = ".chair"; // the class name of elements that should be draggable
var edField = "distance"; // this will be the name of the Embedded Data field with the distance.
var partnerx = "aPosition"; //this will get center x coordinate of Partner Chair
var partnery = "aPosition"; //this will get center y coordinate of Partner Chair
var youx = "bPosition"; //this will get center x coordinate of You Chair
var youy = "bPosition"; //this will get center y coordinate of You Chair
jQuery( function() {
jQuery( draggableClassName ).draggable({
stop: function() {
var distance = getDistanceBetweenElements(document.getElementById("Chair1"),
document.getElementById("Chair2"));
Qualtrics.SurveyEngine.setEmbeddedData('edField', distance);
}
});
});
var getPositionAtCenter = function (element) {
var data = element.getBoundingClientRect();
return {
x: data.left + data.width / 2,
y: data.top + data.height / 2
};
};
var getDistanceBetweenElements = function(a, b) {
var aPosition = getPositionAtCenter(a);
Qualtrics.SurveyEngine.setEmbeddedData('partnerx', aPosition.x);
Qualtrics.SurveyEngine.setEmbeddedData('partnery', aPosition.y);
var bPosition = getPositionAtCenter(b);
Qualtrics.SurveyEngine.setEmbeddedData('youx', bPosition.x);
Qualtrics.SurveyEngine.setEmbeddedData('youy', bPosition.y);
return Math.sqrt(
Math.pow(aPosition.x - bPosition.x, 2) +
Math.pow(aPosition.y - bPosition.y, 2)
);
};
});
Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/
});
Best answer by fleb
Disable your next button at the beginning of your code: `this.disableNextButton();` (e.g.: bellow this line: `Qualtrics.SurveyEngine.addOnReady(function() {`)
In case moving with one chair is sufficient to enable the next button, just enable it again `this.enableNextButton();` in your `stop` function.
In case you want both chairs to be moved:
1) Define the following variables before your `jQuery`:
var moved_CH1 = false;
var moved_CH2 = false;
2) Add this to your `stop` function:
if(this.id == "Chair1") {moved_CH1 = true;}
if(this.id == "Chair2") {moved_CH2 = true;}
if(moved_CH1 = true && moved_CH2 = true) {this.enableNextButton();}
I have tested the first case using click event in Qualtrics and the second case using draggable but outside Qualtrics since implementing the exact copy of your survey in Qualtrics would be too time-consuming for me. Therefore I'm not 100% sure it will work, but I hope so.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
