Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Need Help with Dual Matrix Array Filter

  • nickunz
  • nickunz's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 weeks 3 days ago #268101 by nickunz
LimeSurvey version: Version 5.6.3
Own server or LimeSurvey hosting: Own server
==================Dear all,
I am new to LimeSurvey. I am looking for a way to set up an array filter in a dual matrix that deactivates answer options (or the entire second scale) in Scale 2 if a participant selects a specific answer in Scale 1.If participants select Answer Option 1 or 2 in Scale 1, they might also want to respond to Scale 2 for that row. However, if they choose Answer Option 3 in Scale 1, the answer in Scale 2 becomes redundant or self-explanatory. In such cases, I’d like to deactivate Scale 2 for that particular row.I found this ( forums.limesurvey.org/forum/can-i-do-thi...-dual-matrix?start=0 ) community discussion on the topic, but unfortunately cannot reply to this forum. The script suggested there doesnot work with my LimeSurvey, this might be due to me using a different version. Were there any major changes regarding the use of this script between version 3.4.x and 5.6.3?Thank you in advance for your suggestions!

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 weeks 3 days ago #268102 by tpartner
Replied by tpartner on topic Need Help with Dual Matrix Array Filter
Are you using radios button or dropdown display?

Can you attach a small sample survey (.lss file) containing only the relevant question.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 weeks 3 days ago #268104 by Joffm
Replied by Joffm on topic Need Help with Dual Matrix Array Filter
Hi,
to give some explanation about the versions.

The screenshot you showed seems to be  LimeSurvey Version 2.0 and the last example in the link  (with the dropdowns) is for version 2.50/2.73.

These versions were based on jqueryui, since version 3 LS is based on bootstrap.
So it is not surprising that the scripts do not work in LS 5.x.

Joffm

 

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • nickunz
  • nickunz's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 weeks 3 days ago #268105 by nickunz
Replied by nickunz on topic Need Help with Dual Matrix Array Filter
Hi Tony,

I'm using radio buttons. Attached is a screenshot of the question. The ‘Wahl/Pflicht’ category should only be selectable if 3 or higher has been selected in the ‘Relevanz’ category.

File Attachment:

File Name: limesurvey...27-4.lss
File Size:32 KB

 

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 weeks 3 days ago #268107 by tpartner
Replied by tpartner on topic Need Help with Dual Matrix Array Filter
In version 5.x, add an "N/A" answer to scale-2 and insert this script:

Code:
<script type="text/javascript" data-author="Tony Partner">
 
  $(document).on('ready pjax:scriptcomplete',function() {
 
        // Identify this question
        var thisQuestion = $('#question{QID}');
 
        // Identify the "exclusive" column(s)
        // Multiple columns separated by commas
        var exclusiveCols = [1,2];
 
        // Assign classes to various elements
        $('tr[id^="javatbd"]', thisQuestion).each(function(i){
            var column = 1;
            var scale = 1;
            $('td', this).each(function(i) {
                if($(this).hasClass('answer-item')) {
                    $(this).addClass('scale-'+scale+' column-'+column+'');
                    column++;
                }
                else if(scale == 1 &amp;&amp; $(this).hasClass('dual_scale_separator')) {
                    column = 1;
                    scale = 2;
                }
                else if(scale == 2 &amp;&amp; $(this).hasClass('dual_scale_separator')) {
                    column = 1;
                    scale = 3;
                }
            });
            $('td.scale-2:last', this).addClass('na-item');
        });
        $(exclusiveCols).each(function(i) {
          $('td.scale-1.column-'+this, thisQuestion).addClass('exclusive-item');
        });
 
        // Hide the "N/A" column
        var naIndex = $('td.na-item:eq(0)', thisQuestion).index();
        $('td.na-item', thisQuestion).hide();
        $('.questions-list .dsheader:last', thisQuestion).attr('colspan', Number($('.questions-list thead tr.groups .dsheader:last', thisQuestion).attr('colspan'))-1);
        $('.questions-list thead tr:not(.groups) th.answer-text:not(.noanswer-text):last', thisQuestion).hide();
        $('colgroup.group-2 col:last', thisQuestion).hide();
 
        // Listener on the radios
        $('td.scale-1 input:radio', thisQuestion).on('click', function(e) {
            var thisCell = $(this).closest('td');
            var thisRow = thisCell.closest('tr');
            var thisNA = $('.na-item input:radio', thisRow);
            var naValue = '';
            if(thisCell.hasClass('exclusive-item')) {
                naValue = thisNA.val();
                thisNA.trigger('click');
                $('td.scale-2:not(.na-item) input:radio', thisRow).prop('disabled', true);
            }
            else {
                thisNA.prop('checked', false);
                $('td.scale-2:not(.na-item) input:radio', thisRow).prop('disabled', false);
            }
            // Fire ExpressionScript
            naName = thisNA.attr("name");
            naName = naName.replace('#', '_');
            $("#java" + naName).val(naValue);
            ExprMgr_process_relevance_and_tailoring('change', naValue, 'radio');
        });
 
        // Initial states
        $('td.exclusive-item input:radio:checked', thisQuestion).each(function(i) {
            var thisRow = $(this).closest('tr');
            console.log(thisRow);
            $('.na-item input:radio', thisRow).trigger('click');
            $('td.scale-2:not(.na-item) input:radio', thisRow).prop('disabled', true);
        });
 
    });
</script>

Sample survey attached: 

File Attachment:

File Name: limesurvey...8547.lss
File Size:41 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose