INTRO
- SCHEMA
- Block Randomization
- Inherited Randomization
- Array Filter
- Array Filtering + Inherited Randomization
- Array + Block Randomization + SCHEMA
Case 1 SCHEMA
SCHEMAS are used for array filtering and inheriting randomization; they are an essential part of complex surveys. For example, if you were to use C1
as your initial question code, you would then add the schema C1xSCHEMA
, as shown in the example below.
This schema will inherit the Response ID from the C1
answer, taking into account the randomization. Such a schema could be useful for later questions where you need to insert the answers in the same order they were selected. (The SCHEMA should be naturally hidden)
To add this function, follow these steps:
Step 1: Creating a Single/Multiple-Choice Question
In the selected survey, add a single or multiple-choice question. This question may or may not have randomization activated, but the schema should be useful with this option enabled. This will ensure that the answer IDs from the question are inherited along with their respective randomization.
Step 2: Creating the SCHEMA Question
In the selected survey on the same page as the first question, add a single text question and include the following JavaScript on that page.
/* START EDITING PART */
let questionSchema = "C1xSCHEMA"; // Create a new open text question and set the question code as "QuestionCode"xSCHEMA
/* ENDS EDITING PART */
const checkboxesInput = document.querySelectorAll('.form-check input[type="radio"]');
const checkboxesValues = Array.from(checkboxesInput).map(checkbox => checkbox.value).join(',');
document.querySelector('.form-control').value = checkboxesValues;
document.querySelector(`#q_${questionSchema}_card`).classList.add("d-none");
Ensure to select the corresponding questionSchema
to be the question code of the SCHEMA open text question.
This will allow the schema to inherit the Response ID from the C1
answer, taking into account the randomization.
This code will add the values to the schema and hide it by default.
SynoSurvey example:
This case includes both the single/multiple-choice question with randomization and the single text SCHEMA question on the same page.
Case 2 Block Randomization
Block randomization is used for randomizing certain groups of answers within a question. It allows you to exclude some answers from being randomized or to randomize them with another group of answers, designating them as different blocks of randomization.
For example, this question uses the following groups for block randomization: let randomization = [[1, 2, 3], [4, 5]]
. These groups ensure that answers 1, 2, and 3 will be randomized among themselves within the same block, while answers 4 and 5 will be randomized among each other, without randomizing between the two groups as shown below.
To add this function, follow these steps:
Step 1: Creating a Single/Multiple-Choice Question
In the selected survey, add a single or multiple-choice question. This question must have randomization deactivated. This will ensure that the block randomization will work correctly.
Step 2: Add the JavaScript for block randomization
On the same question, include the following JavaScript.
/* STARTS EDITING PART*/
let questionCode = "C2"; // Question code of the question the code will be added
let randomization = [[1, 2, 3], [4, 5]]; // Add the question answer codes wanted to randomize in one list ([1, 2]) and the ones not wanted to randomized add them to another list ([99])
/* ENDS EDITING PART*/
let scripts = ["https://synocdn.com/js/survey/library/single_choice.js"];
let promises = scripts.map((script) => {
return new Promise((resolve, reject) => {
document.querySelector("body").style.opacity = "0";
let s = document.createElement("script");
s.src = script;
s.onload = resolve;
s.onerror = reject;
document.head.appendChild(s);
});
});
Promise.all(promises)
.then(() => {
/* Function to use */
single_choice({
question_code: questionCode,
randomize: {
answer_groups: randomization,
randomize_groups: false,
}
});
document.querySelector("body").style.opacity = "1";})
/* If a library could not be imported throw an error */
.catch((error) => {
console.error(`Failed to load script: ${error}`);
});
Ensure you select the corresponding questionCode
to be the question code of the same question and define the randomization
groups that you desire for the question by editing the groups in that variable. This will allow the question to randomize the group of answers as you desire.
You can edit the randomization
groups to include as many groups as you want. For example, you can have something similar to this for the randomization
variable:
let randomization = [[1, 2, 3, 4], [5, 6, 7], [8, 9], [99]];
SynoSurvey example:
This case only includes the main single/multiple choice question that contains the block randomization.
Case 3 Inherited Randomization
SCHEMAS are used for array filtering and inheriting randomization; they are an essential part of complex surveys. For example, if you were to use C3x1
as your initial question code, you would then add the schema C3x1xSCHEMA
, as shown in the example below.
This schema will inherit the Response ID from the C3x1
answer, taking into account the randomization. Such a schema is useful for later questions where you need to insert the answers in the same order they were selected, as show on the example below. (The SCHEMA should be naturally hidden)
The schema above saves the randomization from the C3x1
question, which is then used to set the same randomization for the answer options in the C3x2
question below.
To add this function, follow these steps:
Step 1: Creating a Single/Multiple-Choice Question
In the selected survey, add a single or multiple-choice question. This question may or may not have randomization activated, but the schema should be useful with this option enabled. This will ensure that the answer IDs from the question are inherited along with their respective randomization.
Step 2: Creating the SCHEMA Question
In the selected survey on the same page as the first question, add a single text question and include the following JavaScript on that page.
/* START EDITING PART */
let questionSchema = "C3x1xSCHEMA"; // Create a new open text question and set the question code as "QuestionCode"xSCHEMA
/* ENDS EDITING PART */
const checkboxesInput = document.querySelectorAll('.form-check input');
const checkboxesValues = Array.from(checkboxesInput).map(checkbox => checkbox.value).join(',');
document.querySelector('.form-control').value = checkboxesValues;
document.querySelector(`#q_${questionSchema}_card`).classList.add("d-none");
Ensure to select the corresponding questionSchema
to be the question code of the SCHEMA open text question.
This will allow the schema to inherit the Response ID from the C3x1
answer, taking into account the randomization.
This code will add the values to the schema and hide it by default.
Step 3: Creating the Inherited randomization question
In the selected survey, add a new single or multiple-choice question on a new page with the code C3x2
and include the following JavaScript. This question will inherit the randomization stated in the schema.
/* STARTS EDITING PART*/
let questionCode = "C3x2"; // Question code of the question the code will be added
let randomization = "C3x1xSCHEMA"; // Add the question code from the SCHEMA
/* ENDS EDITING PART*/
let scripts = ["https://synocdn.com/js/survey/library/single_choice.js"];
let promises = scripts.map((script) => {
return new Promise((resolve, reject) => {
document.querySelector("body").style.opacity = "0";
let s = document.createElement("script");
s.src = script;
s.onload = resolve;
s.onerror = reject;
document.head.appendChild(s);
});
});
Promise.all(promises)
.then(() => {
/* Function to use */
single_choice({
question_code: questionCode,
randomize: {
filter_schema: randomization, /* Randomized based on previous question */
}
});
document.querySelector("body").style.opacity = "1";})
/* If a library could not be imported throw an error */
.catch((error) => {
console.error(`Failed to load script: ${error}`);
});
SynoSurvey example:
This case includes both the single/multiple-choice question with randomization and the single text SCHEMA question on one page, and on another page, the single/multiple-choice question that inherits the randomization from the previous questions as show below.
Case 4 Array Filter
Array filtering is an essential part of many surveys. With this feature, we can ensure that questions display only the answer options relevant to the panelist, excluding those not previously selected. For example, if the panelist answers "B" and "E" on the C4x1
question, the C4x1SCHEMA
will save the randomization. Then, on the C4x2
Array Filter question, only the "B" and "E" options will be present, making only relevant choices visible to the panelist. (The SCHEMA should be naturally hidden)
To add this function, follow these steps:
Step 1: Creating a Single/Multiple Choice Question
In the selected survey, add a single or multiple-choice question with the code C4x1
. This question may or may not have randomization activated, but the schema should be useful with this option enabled. This will ensure that the answer IDs from the question are inherited along with their respective randomization.
Step 2: Creating the SCHEMA Question
In the selected survey on the same page as the first question, add a single text question with the code C4x1SCHEMA
and include the following JavaScript on that page.
/* START EDITING PART */
let questionSchema = "C4x1xSCHEMA"; // Create a new open text question and set the question code as "QuestionCode"xSCHEMA
/* ENDS EDITING PART */
function setSCHEMA(questionSchema) {
const checkboxesInput = document.querySelectorAll(`.form-check input`);
const checkboxesValues = Array.from(checkboxesInput).map(checkbox => checkbox.value).join(',');
document.querySelector('.form-control').value = checkboxesValues;
document.querySelector(`#q_${questionSchema}_card`).classList.add("d-none");
}
setSCHEMA(questionSchema);
Ensure to select the corresponding questionSchema
to be the question code of the SCHEMA open text question.
This will allow the schema to inherit the Response ID from the C4x1
answer, taking into account the randomization.
This code will add the values to the schema and hide it by default.
Step 3: Creating the Array Filter question
In the selected survey, add a new single or multiple-choice question on a new page with the code C4x2
and include the following JavaScript. This question will only show the answer options from the C4x1
question, thereby only displaying relevant options to the respondent.
/* STARTS EDITING PART*/
let questionCode = "C4x2"; // Question code of the question the code will be added
let questionFilteredCode = "C4x1"; // Question code of the question wanted to filter from
let questionFilteredCodeSchema = "C4x1xSCHEMA"; // Question code of the question wanted to filter from
let inclusiveOrExclusive = "inclusive"; // Set as "inclusive" to get questions selected // Set as "exclusive" for questions not selected
/* ENDS EDITING PART*/
let scripts = ["https://synocdn.com/js/survey/library/single_choice.js"];
let promises = scripts.map((script) => {
return new Promise((resolve, reject) => {
document.querySelector("body").style.opacity = "0";
let s = document.createElement("script");
s.src = script;
s.onload = resolve;
s.onerror = reject;
document.head.appendChild(s);
});
});
Promise.all(promises)
.then(() => {
/* Function to use */
single_choice({
question_code: questionCode,
array_filter: {
filter: questionFilteredCode,
filter_schema: questionFilteredCodeSchema,
type: inclusiveOrExclusive,
},
});
document.querySelector("body").style.opacity = "1";})
/* If a library could not be imported throw an error */
.catch((error) => {
console.error(`Failed to load script: ${error}`);
});
Ensure to select the corresponding questionCode
and questionFilteredSchema
to be the question codes from the C4x2
question and the C4x1 SCHEMA
question. Also, take into account that you are able to change the inclusiveOrExclusive
variable into either "inclusive" or "exclusive" to either include the question answers selected on the C4x1
question or to exclude them.
Case 5 Array Filtering + Inherited Randomization
Array filtering is crucial in surveys, ensuring that questions display only relevant answer options based on the panelist's selections, while excluding those that are not chosen (or the other way around). By inheriting randomization, selected answers on the initial question retain their randomized order on a SCHEMA
for subsequent use in other questions or in array filtering, maintaining consistency with how they were presented to the respondent. This Case effectively combines both functionalities.
For example, if the panelist answers "B" and "E" on the C5x1
question, the C5x1SCHEMA
will save the randomization. Then, on the C5x2
Array Filter question, only the "B" and "E" options will be present, making only relevant choices visible to the panelist. (The SCHEMA should be naturally hidden)
To add this function, follow these steps:
Step 1: Creating a Single/Multiple Choice Question
In the selected survey, add a single or multiple-choice question with the code C5x1
. This question may or may not have randomization activated, but the schema should be useful with this option enabled. This will ensure that the answer IDs from the question are inherited along with their respective randomization.
Step 2: Creating the SCHEMA Question
In the selected survey on the same page as the first question, add a single text question with the code C5x1SCHEMA
and include the following JavaScript on that page.
/* START EDITING PART */
let questionSchema = "C5x1xSCHEMA"; // Create a new open text question and set the question code as "QuestionCode"xSCHEMA
/* ENDS EDITING PART */
function setSCHEMA(questionSchema) {
const checkboxesInput = document.querySelectorAll(`.form-check input`);
const checkboxesValues = Array.from(checkboxesInput).map(checkbox => checkbox.value).join(',');
document.querySelector('.form-control').value = checkboxesValues;
document.querySelector(`#q_${questionSchema}_card`).classList.add("d-none");
}
setSCHEMA(questionSchema);
Ensure to select the corresponding questionSchema
to be the question code of the SCHEMA
open text question.
This will allow the schema to inherit the Response ID from the C5x1
answer, taking into account the randomization.
This code will add the values to the schema and hide it by default..
Step 3: Creating the Array Filter question
In the selected survey, add a new single or multiple-choice question on a new page with the code C5x2
and include the following JavaScript. This question will only show the answer options from the C5x1
question, thereby only displaying relevant options to the respondent.
/* STARTS EDITING PART*/
let questionCode = "C5x2"; // Question code of the question the code will be added
let questionFilteredCode = "C5x1"; // Question code of the question wanted to filter from
let questionFilteredCodeSchema = "C5x1xSCHEMA"; // Question code of the question wanted to filter from
let inclusiveOrExclusive = "inclusive"; // Set as "inclusive" to get questions selected // Set as "exclusive" for questions not selected
/* ENDS EDITING PART*/
let scripts = ["https://synocdn.com/js/survey/library/single_choice.js"];
let promises = scripts.map((script) => {
return new Promise((resolve, reject) => {
document.querySelector("body").style.opacity = "0";
let s = document.createElement("script");
s.src = script;
s.onload = resolve;
s.onerror = reject;
document.head.appendChild(s);
});
});
Promise.all(promises)
.then(() => {
/* Function to use */
single_choice({
question_code: questionCode,
array_filter: {
filter: questionFilteredCode,
filter_schema: questionFilteredCodeSchema,
type: inclusiveOrExclusive,
},
});
document.querySelector("body").style.opacity = "1";})
/* If a library could not be imported throw an error */
.catch((error) => {
console.error(`Failed to load script: ${error}`);
});
Ensure to select the corresponding questionCode
and questionFilteredSchema
to be the question codes from the C5x2
question and the C5x1 SCHEMA
question. Also, take into account that you are able to change the inclusiveOrExclusive
variable into either "inclusive" or "exclusive" to either include the question answers selected on the C5x1
question or to exclude them.
Case 6 Array + Block Randomization + SCHEMA
Array filtering is essential in surveys to ensure that questions display only relevant answer options based on the panelist's selections, while excluding irrelevant ones. Additionally, block randomization is employed to randomize specific groups of answers within a question. This method allows for excluding certain answers from randomization or grouping them with others into distinct blocks for randomized presentation.
By inheriting randomization, the selected answers from the initial question maintain their randomized order in a schema. This consistency ensures that subsequent questions or array filtering tasks present answers in the same randomized sequence as initially presented to the respondent. This Case effectively integrates these three functionalities.
For instance, consider the following block randomization setup: randomization = [[1, 2, 3], [4, 5]]
. This configuration ensures that answers 1, 2, and 3 are randomized within their block, and answers 4 and 5 are randomized within their block, with no mixing between the two groups.
If a panelist selects "B" and "E" in response to the C6x1
question, the C6x1SCHEMA
will store this randomization, taking into account the block randomization structure. Subsequently, in the C6x2
Array Filter question, only the options "B" and "E" will be available, ensuring that only relevant choices are presented to the panelist.
To add this function, follow these steps:
Step 1: Creating a Single/Multiple Choice Question
In the selected survey, add a single or multiple-choice question with the code C5x1
. This question may or may not have randomization activated, but the schema should be useful with this option enabled. This will ensure that the answer IDs from the question are inherited along with their respective randomization.
Step 2: Creating the SCHEMA Question
In the selected survey on the same page as the first question, add a single text question with the code C5x1SCHEMA
and include the following JavaScript on that page.
/* START EDITING PART */
let questionSchema = "C5x1xSCHEMA"; // Create a new open text question and set the question code as "QuestionCode"xSCHEMA
/* ENDS EDITING PART */
function setSCHEMA(questionSchema) {
const checkboxesInput = document.querySelectorAll(`.form-check input`);
const checkboxesValues = Array.from(checkboxesInput).map(checkbox => checkbox.value).join(',');
document.querySelector('.form-control').value = checkboxesValues;
document.querySelector(`#q_${questionSchema}_card`).classList.add("d-none");
}
setSCHEMA(questionSchema);
Ensure to select the corresponding questionSchema
to be the question code of the SCHEMA
open text question.
This will allow the schema to inherit the Response ID from the C5x1
answer, taking into account the randomization.
This code will add the values to the schema and hide it by default..
Step 3: Creating the Array Filter question
In the selected survey, add a new single or multiple-choice question on a new page with the code C5x2
and include the following JavaScript. This question will only show the answer options from the C5x1
question, thereby only displaying relevant options to the respondent.
/* STARTS EDITING PART*/
let questionCode = "C5x2"; // Question code of the question the code will be added
let questionFilteredCode = "C5x1"; // Question code of the question wanted to filter from
let questionFilteredCodeSchema = "C5x1xSCHEMA"; // Question code of the question wanted to filter from
let inclusiveOrExclusive = "inclusive"; // Set as "inclusive" to get questions selected // Set as "exclusive" for questions not selected
/* ENDS EDITING PART*/
let scripts = ["https://synocdn.com/js/survey/library/single_choice.js"];
let promises = scripts.map((script) => {
return new Promise((resolve, reject) => {
document.querySelector("body").style.opacity = "0";
let s = document.createElement("script");
s.src = script;
s.onload = resolve;
s.onerror = reject;
document.head.appendChild(s);
});
});
Promise.all(promises)
.then(() => {
/* Function to use */
single_choice({
question_code: questionCode,
array_filter: {
filter: questionFilteredCode,
filter_schema: questionFilteredCodeSchema,
type: inclusiveOrExclusive,
},
});
document.querySelector("body").style.opacity = "1";})
/* If a library could not be imported throw an error */
.catch((error) => {
console.error(`Failed to load script: ${error}`);
});
Ensure to select the corresponding questionCode
and questionFilteredSchema
to be the question codes from the C5x2
question and the C5x1 SCHEMA
question. Also, take into account that you are able to change the inclusiveOrExclusive
variable into either "inclusive" or "exclusive" to either include the question answers selected on the C5x1
question or to exclude them.
For this we will need to take 2 steps:
- Add a SCHEMA to the original question, the one from which we are getting the randomization.
- Add JS to the desired question while adjusting the code.
For this, you will need to add the following JS to the original question to add the SCHEMA and adjust randomized answers on the JS.
/* START EDITING PART */
let questionSchema = "C6x1xSCHEMA"; // Create a new open text question and set the question code as "QuestionCode"xSCHEMA
const typeOfQuestion = "radio" //Use checkbox for multiple and radio for single
let questionCode = "C6x1"; // Question code of the question the code will be added
let randomization = [[1, 2, 3, 4], [5]]; // Add the question answer codes wanted to randomize in one list ([1, 2]) and the ones not wanted to randomized add them to another list ([99])
/* ENDS EDITING PART */
function setSCHEMA(questionSchema) {
const checkboxesInput = document.querySelectorAll(`.form-check input[type="${typeOfQuestion}"]`);
const checkboxesValues = Array.from(checkboxesInput).map(checkbox => checkbox.value).join(',');
document.querySelector('.form-control').value = checkboxesValues;
document.querySelector(`#q_${questionSchema}_card`).classList.add("d-none");
}
setSCHEMA(questionSchema);
let scripts = ["https://synocdn.com/js/survey/library/single_choice.js"];
let promises = scripts.map((script) => {
return new Promise((resolve, reject) => {
document.querySelector("body").style.opacity = "0";
let s = document.createElement("script");
s.src = script;
s.onload = resolve;
s.onerror = reject;
document.head.appendChild(s);
});
});
Promise.all(promises)
.then(() => {
/* Function to use */
single_choice({
question_code: questionCode,
randomize: {
answer_groups: randomization,
randomize_groups: false,
}
});
document.querySelector("body").style.opacity = "1";})
/* If a library could not be imported throw an error */
.catch((error) => {
console.error(`Failed to load script: ${error}`);
});
And you will get the following results
/* STARTS EDITING PART*/
let questionCode = "C6x2"; // Question code of the question the code will be added
let questionFilteredCode = "C6x1"; // Question code of the question wanted to filter from
let questionFilteredCodeSchema = "C6x1xSCHEMA"; // Question code of the question wanted to filter from
let inclusiveOrExclusive = "inclusive"; // Set as "inclusive" to get questions selected // Set as "exclusive" for questions not selected
let randomization = "C6x1xSCHEMA"; // Add the question code from the SCHEMA
/* ENDS EDITING PART*/
let scripts = ["https://synocdn.com/js/survey/library/single_choice.js"];
let promises = scripts.map((script) => {
return new Promise((resolve, reject) => {
document.querySelector("body").style.opacity = "0";
let s = document.createElement("script");
s.src = script;
s.onload = resolve;
s.onerror = reject;
document.head.appendChild(s);
});
});
Promise.all(promises)
.then(() => {
/* Function to use */
single_choice({
question_code: questionCode,
randomize: {
filter_schema: randomization,
},
array_filter: {
filter: questionFilteredCode,
filter_schema: questionFilteredCodeSchema,
type: inclusiveOrExclusive,
},
});
document.querySelector("body").style.opacity = "1";})
/* If a library could not be imported throw an error */
.catch((error) => {
console.error(`Failed to load script: ${error}`);
});