Hello,
I have a complex array filter to set up under Version 3.19.1+191009, I have spent many hours reading the manual and the forums but have not managed to implement a solution so far. I understand how to implement an existing JavaScript code in a survey but cannot write code from scratch.
An example survey with 5 questions is in attachment. B9 is the question on which I would like to set up an array filter based on B9filter, but it's currently not working. B9 filter gets its options from two different multiple choice questions and I have added JavaScript to automatically check the boxes, but I'm not sure this is the right way to do it.
Ideally, I would have liked to use this to filter the answer options in a array by column question (B9b), but I'm not sure this is feasible at all and would already be grateful if B9 could work.
The details of the questions are below.
Kind regards,
Séverine
-Question A7a (multiple-choice): people select various activities
-Question A7b (multiple-choice): if people select options 7 or 8 at A7a, this questions appears with another list of activities
-B9filter (hidden multiple-choice): a question that picks up the answers to A7a and A7b using relevance equations. I have added JavaScript to check the boxes by default, but I'm not sure this is working as intended.
-B9: a radio list question that should be filtered with an array filter on B9filter but is currently not working
-B9b: what I would ideally need, an array by column with the answer options filtered on B9filter. If that's not possible, I can split the two columns in two radio list questions like B9.
In that case, I would use this JavaScript in the source of B9filter - it will only check relevant items and will also fire Expression Manager so the filter on B9 is activated.
Thank you, this works perfectly! I would of course be grateful if you find a solution for B9b, but this already allows us to move on with testing the questionnaire further.
Here is the JS solution for filtering array-by-column rows based on a hidden multiple-choice question. The workaround assumes that the multiple choice question is in the same group and precedes the array question.
Code:
<script type="text/javascript" data-author="Tony Partner">
$(document).on('ready pjax:scriptcomplete',function(){
// Identify this question
var qID = {QID};
var thisQuestion = $('#question'+qID);
var filterQuestion = thisQuestion.prevAll('.multiple-opt:eq(0)');
var filterQID = filterQuestion.attr('id').replace(/question/, '');
// Loop through irrelevant items in the filter question
$('.answer-item.ls-irrelevant', filterQuestion).each(function(i) {
var thisCode = $(this).attr('id').split('X'+filterQID)[1];
var arrayRow = $('input:radio[value="'+thisCode+'"]:eq(0)', thisQuestion).closest('tr');
// Hide the corresponding row in the array question
arrayRow.addClass('ls-hidden');
// Un-check the radios in the corresponding row (in case of previous answers)
$('input:radio', arrayRow).each(function(i) {
var thisInput = $(this);
thisInput.prop('checked', false);
checkconditions('', thisInput.attr('name'), 'radio')
});
});
});
</script>