-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added some more functions. Didn't have the time to write details.
- Loading branch information
Showing
7 changed files
with
297 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
Qualtrics.SurveyEngine.addOnload(function() | ||
{ | ||
//Create a placeholder to display the reminder message | ||
char_rem = document.createElement("p"); | ||
char_rem.setAttribute("id", "char_reminder"); | ||
char_rem.setAttribute("style", "color:LightGray;"); | ||
this.getChoiceContainer().parentNode.appendChild(char_rem); | ||
|
||
}); | ||
|
||
Qualtrics.SurveyEngine.addOnReady(function() | ||
{ | ||
const qid = this.questionId; | ||
document.querySelector("#QR\\~" + qid).oninput = function () {limited();}; | ||
|
||
function limited(){ | ||
curr_len = document.querySelector("#QR\\~" + qid).value.length; | ||
|
||
//Set the max_len as an embedded data field equal to maximum length in validation options | ||
max_len = "${e://Field/max_len}"; | ||
//Nothing will be displayed if the characters are less than 10 | ||
//If you want to always have the reminder, then delete the statement below and remove the if condition | ||
reminder = ""; | ||
if(curr_len>10){ | ||
rem_len = max_len - curr_len; | ||
reminder = rem_len + "/20 characters remaining"; | ||
} | ||
document.querySelector("#char_reminder").innerText = reminder; | ||
} | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
Qualtrics.SurveyEngine.addOnload(function () { | ||
//Diables the next button at the start | ||
// You can delete this if you are fine with the sum as being zero | ||
this.disableNextButton(); | ||
}); | ||
|
||
Qualtrics.SurveyEngine.addOnReady(function () { | ||
//Get the Question Id | ||
const qid = this.questionId; | ||
// Get the number of choices | ||
n_choices = Qualtrics.SurveyEngine.registry[qid].getChoices(); | ||
|
||
const base_msg = jQuery("#"+qid+" .QuestionText").html(); | ||
|
||
// Detect a change in any of the choices | ||
n_choices.forEach((item) => { | ||
console.log("input detected"); | ||
document.querySelector("#QR\\~" + qid + "\\~" + item).oninput = function () {chk_sum();}; | ||
}); | ||
|
||
that = this; | ||
function chk_sum() { | ||
var max_sum = parseInt("${e://Field/max_sum}"); | ||
var current_sum = 0; | ||
|
||
padding_pre = '<br> <a style="color:red;">'; | ||
padding_post = '</a>'; | ||
err_msg = "The total should be more than zero and less than " + max_sum + " to proceed"; | ||
|
||
//Iterate over each of choices | ||
n_choices.forEach((item) => { | ||
curr_val = parseInt(document.querySelector("#QR\\~" + qid + "\\~" + item).value); | ||
// Check for empty blocks | ||
if (isNaN(curr_val)) { | ||
if (document.querySelector("#QR\\~" + qid + "\\~" + item).value == "") { | ||
curr_val = 0; | ||
} else { | ||
|
||
err_msg = "Please enter only valid integer numbers."; | ||
} | ||
} | ||
//Check for invalid characters | ||
if (document.querySelector("#QR\\~" + qid + "\\~" + item).value.search(/\D/) != -1){ | ||
err_msg = "Please enter only valid integer numbers."; | ||
curr_val = max_sum + 1; | ||
|
||
} | ||
current_sum += curr_val; | ||
}); | ||
err_msg = base_msg + padding_pre + err_msg + padding_post; | ||
|
||
//Checks for zero and the value being more than zero and less than the max_sum | ||
// If you are fine with zero then delete "current_sum >0 &&" | ||
if (current_sum > 0 && current_sum <= max_sum) { | ||
that.enableNextButton(); | ||
jQuery("#"+qid+" .QuestionText").html(base_msg); | ||
} else { | ||
that.disableNextButton(); | ||
jQuery("#"+qid+" .QuestionText").html(err_msg); | ||
} | ||
} | ||
}); |
40 changes: 40 additions & 0 deletions
40
JavaScript Files/Highlight unanswered questions_Request Response.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
let my_interval; | ||
Qualtrics.SurveyEngine.addOnReady(function(){ | ||
let attempt = 1; | ||
document.querySelector("#NextButton").onclick = function() { | ||
my_interval = setInterval(() => { | ||
err_msg = document.querySelector("#ErrorMessage"); | ||
if (err_msg != null) { | ||
console.log("done"); | ||
solver(); | ||
clearInterval(my_interval); | ||
} | ||
}, 10); | ||
|
||
}; | ||
that = this; | ||
var n = jQuery("#"+this.questionId+" .ChoiceRow").length; | ||
function solver (){ | ||
attempt++; | ||
for(var i=0;i<n;i++){ | ||
if(jQuery("#"+that.questionId+" .ChoiceRow:eq("+i+") td input[type='radio']:checked").length==0){ | ||
jQuery("#"+that.questionId+" .ChoiceRow:eq("+i+")").css("background","lightpink"); | ||
} | ||
} | ||
} | ||
this.questionclick = function(){ | ||
if(attempt>1){ | ||
console.log("test"); | ||
for(var i=0;i<n;i++){ | ||
if(jQuery("#"+that.questionId+" .ChoiceRow:eq("+i+") td input[type='radio']:checked").length!=0){ | ||
jQuery("#"+that.questionId+" .ChoiceRow:eq("+i+")").css("background",""); | ||
} | ||
} | ||
|
||
} | ||
} | ||
}); | ||
|
||
Qualtrics.SurveyEngine.addOnUnload(function() { | ||
clearInterval(my_interval); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
Qualtrics.SurveyEngine.addOnload(function () { | ||
var time_calc; | ||
}); | ||
|
||
Qualtrics.SurveyEngine.addOnReady(function () { | ||
|
||
//Get the remaning time | ||
var rem_time = "${e://Field/remaining_time}"; | ||
rem_time = parseInt(rem_time); | ||
that = this; | ||
time_calc = setInterval(function () { | ||
rem_time = rem_time - 1; | ||
|
||
// Update the remaining time every second | ||
Qualtrics.SurveyEngine.setEmbeddedData("remaining_time", rem_time); | ||
|
||
if (rem_time <= 0) { | ||
clearInterval(time_calc); | ||
// This line will create and alert that time is up. Delete it or you may change its text as you please. | ||
alert("times up"); | ||
|
||
// This will skip the other questions and go the end of the block | ||
// Ensure that you have display logic set up accordingly | ||
Qualtrics.SurveyEngine.setEmbeddedData("time_over", "TRUE"); | ||
// Auto advance | ||
that.clickNextButton(); | ||
} | ||
}, 1000); | ||
}); | ||
|
||
Qualtrics.SurveyEngine.addOnUnload(function() | ||
{ | ||
clearInterval(time_calc); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Qualtrics.SurveyEngine.addOnReady(function(){ | ||
const qid = this.questionId; | ||
tot_choices = Qualtrics.SurveyEngine.registry[qid].getChoices().length; | ||
var sel_choices = 0; | ||
|
||
that = this; | ||
this.questionclick = function(){ | ||
sel_choices = that.getSelectedChoices().length; | ||
} | ||
|
||
document.querySelector("#NextButton").onmousedown = function() {check_answers();}; | ||
|
||
|
||
function check_answers(){ | ||
if (sel_choices == tot_choices){that.clickNextButton();} | ||
else{ | ||
//Selecting Okay will result in continuing | ||
if (confirm("Custom message here") == true) { | ||
that.clickNextButton(); | ||
} | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Log values as they are typed | ||
|
||
|
||
document.getElementById("submit").onclick = function() {userInput()}; | ||
arr = []; | ||
function userInput() | ||
{ | ||
var input = document.getElementById("userInput").value; | ||
arr.push(input); | ||
//seEmbeddedData doesn't need QuestionData | ||
//The name of the Embedded Data variable needs to be passed as a string | ||
//In you case, it was trying to parse the value of url_list, which was undefined | ||
Qualtrics.SurveyEngine.setEmbeddedData("url_list", arr); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
Qualtrics.SurveyEngine.addOnReady(function() | ||
{ | ||
//Create a placeholder to display the reminder message | ||
// ques_cover = document.createElement("div"); | ||
// ques_cover.setAttribute("id", "ques_cover"); | ||
// ques_cover.setAttribute("class", "overlay"); | ||
var overlay = jQuery('<div id="overlay"> </div>'); | ||
overlay.appendTo(this.getQuestionContainer()); | ||
// ques_cover.appendTo(this.getQuestionContainer()); | ||
// this.getQuestionContainer().appendChild(ques_cover); | ||
|
||
|
||
var ov_css = `#overlay { | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
background-color: #000; | ||
filter:alpha(opacity=50); | ||
-moz-opacity:0.5; | ||
-khtml-opacity: 0.5; | ||
opacity: 0.5; | ||
z-index: 10000; | ||
}` | ||
|
||
var styleSheet = document.createElement("style"); | ||
styleSheet.type = "text/css"; | ||
styleSheet.innerText = ov_css; | ||
document.head.appendChild(styleSheet); | ||
|
||
setTimeout(() => { | ||
overlay.remove(); | ||
|
||
}, 3000); | ||
that = this; | ||
setTimeout(() => { | ||
overlay = jQuery('<div id="overlay"> </div>'); | ||
overlay.appendChild(that.getQuestionContainer()); | ||
|
||
}, 3000); | ||
setTimeout(() => { | ||
overlay.remove(); | ||
|
||
}, 3000); | ||
|
||
}); | ||
|
||
let my_interval; | ||
Qualtrics.SurveyEngine.addOnReady(function(){ | ||
let elem = document.querySelector("#Page > div"); | ||
let observer = new MutationObserver(mutationRecords => { | ||
// console.log(mutationRecords); // console.log(the changes) | ||
|
||
my_interval = setInterval(() => { | ||
err_msg = document.querySelector("#ErrorMessage"); | ||
if (err_msg != null) { | ||
err_msg.innerText = "Custom Message"; | ||
console.log(err_msg.innerText); | ||
clearInterval(my_interval); | ||
my_interval = null; | ||
} | ||
}, 100); | ||
}); | ||
|
||
|
||
|
||
observer.observe(elem, { | ||
childList: true, // observe direct children | ||
subtree: true, // and lower descendants too | ||
characterDataOldValue: true // pass old data to callback | ||
}); | ||
|
||
}); | ||
|
||
let my_interval; | ||
Qualtrics.SurveyEngine.addOnReady(function(){ | ||
|
||
document.querySelector("#NextButton").onclick = function() { | ||
my_interval = setInterval(() => { | ||
err_msg = document.querySelector("#ErrorMessage"); | ||
if (err_msg != null) { | ||
err_msg.innerText = "Custom Message"; | ||
clearInterval(my_interval); | ||
} | ||
}, 10); | ||
|
||
}; | ||
}); | ||
|
||
Qualtrics.SurveyEngine.addOnUnload(function() { | ||
clearInterval(my_interval); | ||
}); |