In this tutorial, you will learn how to recode brands according to specified regions/countries.
First, let's add a new single or multiple choice question with all the regions or countries you want to recode from.
In another page, create your filter where brands will be recoded.
In the same page of the recode, create an open text to dump the question schema.
Good to know
A schema contains the answer codes and their order for the current question. This is required if you need to apply an array filter or randomize subsequent questions in the same order.
function recode({ question_code, filter, dictionary, test_mode} = {}) {
var question_card = document.querySelector("#q_" + question_code + "_card");
var options_container = question_card.querySelector("#p_" + question_code);
var form_checks = question_card.querySelectorAll(".form-check");
var answer_options = {};
form_checks.forEach((form_check, index) => {
var input = form_check.querySelector("input");
var code = input.value;
var label = form_check.querySelector("label > div > div").innerText;
var open_text = form_check.querySelector("label > div:nth-child(2) > input");
answer_options[code] = { "form_check": form_check, "input": input, "label": label, "open_text": open_text };
});
// Clear all the options
for (let [code, value] of Object.entries(answer_options)) {
value.input.checked = false;
}
// Check options according to each region/country in hashmap dictionary
response.answers.forEach((answer) => {
if (answer.questionCode == filter) {
var elements = dictionary[answer.code];
for (let [code, value] of Object.entries(answer_options)) {
if (elements.includes(Number(code))) {
value.input.checked = true;
}
}
}
});
if(test_mode === undefined || test_mode == false){
// Hides the page and go to next page
document.querySelector("body").style.display = "none";
document.querySelector("#p_next").click();
} else if(test_mode == true){
// Shows the page if testing
document.querySelector("body").style.display = "flex";
}
}