Welcome to the LimeSurvey Community Forum

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

Array filter with exclusive option

  • wireframemedia
  • wireframemedia's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
14 years 3 months ago #48271 by wireframemedia
Array filter with exclusive option was created by wireframemedia
I have a very complex survey which uses a lot of array filters to feed answers from other questions. I have one question which also requires an exclusive option to appear along with the filtered results. How can I accomplish this? The filtering seems to work fine but the exclusive option does not show up.

Thank you.
d.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
14 years 3 months ago #48280 by tpartner
Replied by tpartner on topic Array filter with exclusive option
If I understand correctly, you want one option of the array to always show and all others to be filtered by a multi-opt question.

To do this you will need to build your own filter with JavaScript.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • wireframemedia
  • wireframemedia's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
14 years 3 months ago #48281 by wireframemedia
Replied by wireframemedia on topic Array filter with exclusive option
Hi Tony,

Yes that is exactly what I need to do. Can you provide a bit more direction and a sample of the code needed to accomplish this? I am new to LimeSurvey.

Thank you.

Dawna
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
14 years 3 months ago #48282 by tpartner
Replied by tpartner on topic Array filter with exclusive option
Okay, this should do the trick for an array that uses radio buttons (not array-multi-flexible-numbers or array-multi-flexible-text).

Set up your survey to use JavaScript and place the following script in the source of the multi-option question.

Replace "111" (line 6) with the multi-option question ID and "222" (line 7) with the array question ID.

Note that the answer codes of both questions MUST be identical EXCEPT for the answer code of the option that you want permanently displayed.
Code:
<script type="text/javascript" charset="utf-8">
 
    // Filter array by multi-opt but always show default option
    $(document).ready(function(){
 
        var q1ID = 111;                       
        var q2ID = 222;
 
        // Find the survey and group IDs
        if($( 'input#fieldnames' ).length != 0) {
            var fieldNames = $('input#fieldnames').attr('value');
            var tmp = fieldNames.split('X');
            var sID = tmp[0];
            var gID = tmp[1];
        }
 
        var optionCode = '';
 
        // Initially hide and clear all unwanted array rows
        $('#question'+q1ID+' input.checkbox').each(function(i) {
 
            inputID = $(this).attr('id');
            var tmp2 = inputID.split(q1ID);
            var optionCode = tmp2[1];
 
            if ($(this).attr('checked') == false) {
                $('#question'+q2ID+' table.question tbody#javatbd'+sID+'X'+gID+'X'+q2ID+optionCode+'').hide();
 
                $('#question'+q2ID+' table.question tbody#javatbd'+sID+'X'+gID+'X'+q2ID+optionCode+' input.radio').each(function(i) {
                    $(this).attr('checked', false);
                });
            }
        });
 
        // Listener on radio inputs
        $('#question'+q1ID+' td.answer, #question'+q1ID+' td.answer input.checkbox').click(function() {
 
            // Hide and clear all unwanted array rows
            $('#question'+q1ID+' input.checkbox').each(function(i) {
 
                inputID = $(this).attr('id');
                var tmp2 = inputID.split(q1ID);
                var optionCode = tmp2[1];
 
                if ($(this).attr('checked') == false) {
                    $('#question'+q2ID+' table.question tbody#javatbd'+sID+'X'+gID+'X'+q2ID+optionCode+'').hide();
 
                    $('#question'+q2ID+' table.question tbody#javatbd'+sID+'X'+gID+'X'+q2ID+optionCode+' input.radio').each(function(i) {
                        $(this).attr('checked', false);
                    });
                }
                else {
                    $('#question'+q2ID+' table.question tbody#javatbd'+sID+'X'+gID+'X'+q2ID+optionCode+'').show();
                }
            });
 
        });
 
    });
 
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
14 years 3 months ago #48291 by Mazi
Replied by Mazi on topic Array filter with exclusive option
Just because of interest: What happens if there is an additional answer item in a following question that doesn't exist at the previous multiple choice question?
Will it not be listed at all when using array filter?

Best regards/Beste Grüße,
Dr. Marcel Minke
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
14 years 3 months ago #48294 by tpartner
Replied by tpartner on topic Array filter with exclusive option
Yeah, if you enable the array filter in advanced settings, no options will be shown in the array unless they are checked in the multi-options question. This includes array options that don't exist in the multi-options question.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
14 years 3 months ago #48307 by Mazi
Replied by Mazi on topic Array filter with exclusive option
Thanks for clarifying!

Best regards/Beste Grüße,
Dr. Marcel Minke
The topic has been locked.
  • wireframemedia
  • wireframemedia's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
14 years 3 months ago - 14 years 3 months ago #48311 by wireframemedia
Replied by wireframemedia on topic Array filter with exclusive option
Tony,

Thank you so much, this is great!

I tried it but the exclusive option is still not showing up. I have to use checkboxes (not radio buttons) for multiple responses; could that be why it is not working?

Along with the exclusive option, I need the "other option" to also show up regardless of the answers/filter piping in from a previous question so those two will be constants.

Thanks.
Dawna
Last edit: 14 years 3 months ago by wireframemedia.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
14 years 3 months ago #48321 by tpartner
Replied by tpartner on topic Array filter with exclusive option

...the exclusive option is still not showing up...

Did you disable the array filter in the advance settings for the array question?

Along with the exclusive option, I need the "other option" to also show up regardless of the answers/filter piping in from a previous question so those two will be constants.

I'll have to look into that tonight.

I have to use checkboxes (not radio buttons) for multiple responses

The script is designed for a multi-options (checkbox) followed by an array (radio buttons) question.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • wireframemedia
  • wireframemedia's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
14 years 3 months ago - 14 years 3 months ago #48322 by wireframemedia
Replied by wireframemedia on topic Array filter with exclusive option
Hi Tony,

Yes I did and when I did that, all original options showed up, none of the previously selected options appeared (no filtering) so I re-inserted it. I'll remove it again but then it does not filter at all. I did a JavaScript test and it is reading JS fine, just not doing what we want yet.

The survey requires a multi-option (checkbox) array followed by another multi-option (checkbox) array filtered and including the exclusive option and other option as well....very complicated but it's for a high-end client and it's what they want.

Thank you for your help. I appreciate it.
d.
Last edit: 14 years 3 months ago by wireframemedia.
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
14 years 3 months ago #48323 by Mazi
Replied by Mazi on topic Array filter with exclusive option
Note that question IDs change when setting up a new question so don't forget to adjust the IDs.

Best regards/Beste Grüße,
Dr. Marcel Minke
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
14 years 3 months ago #48350 by tpartner
Replied by tpartner on topic Array filter with exclusive option

The survey requires a multi-option (checkbox) array followed by another multi-option (checkbox) array filtered and including the exclusive option and other option as well...

Hmm...now I'm a little confused. I thought you were filtering an array with a multiple options question (see my screenshot).

Can you activate a sample survey or provide a screenshot?


Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose