Hi,
they were to complex to implement.
pardon, but what is too complex to implement one of these two "standared" solutions.
1. Split the questions into two groups
a. group 1 (visible) with x questions
b. group 2 (hidden) with the rest, y-x questions.
All questions get the same randomization group name.
Group 1:
- Question 1
- Question 2
- Question 3
- Question 4
Group 2 (hidden with "condition 0"):
- Question 5
- Question 6
- Question 7
- Question 8
- Question 9
- Question 10
2. A small javascript snippet to select randomly x out of y elements
You may use randomization groups or not.
And display the questions with the condition(s) (if I call the question with the javascript "QPool"):
strpos(QPool,"001")>0
strpos(QPool,"002")>0
strpos(QPool,"003")>0
Code:
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
while (0 !== currentIndex) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
$(document).on('ready pjax:scriptcomplete',function(){
// Fill the array
let countAllQuestions = 10;
let countShown = 4;
var arr = [];
for (var i = 1; i <= countAllQuestions; i++) {
arr.push(('00'+i).slice(-3));
}
arr = shuffle(arr).slice(0,countShown).join(',');
$('#question{QID} input[type="text"]').val('#'+arr);
$('#question{QID}').hide();
});
</script>
This script can handle up to 999 questions
arr.push(('00'+i).slice(-3));
You may hide this script either by javascript
$('#question{QID}').hide(); or by the css clss "
d-none"
.
Joffm