Welcome, Guest
Username: Password: Remember me

TOPIC: Array filter with exclusive option

Array filter with exclusive option 4 years 1 month ago #48271

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 administrator has disabled public write access.

Re:Array filter with exclusive option 4 years 1 month ago #48280

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4272
  • Thank you received: 806
  • Karma: 369
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re:Array filter with exclusive option 4 years 1 month ago #48281

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 administrator has disabled public write access.

Re:Array filter with exclusive option 4 years 1 month ago #48282

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4272
  • Thank you received: 806
  • Karma: 369
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.
<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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re:Array filter with exclusive option 4 years 1 month ago #48291

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5331
  • Thank you received: 296
  • Karma: 249
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
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Re:Array filter with exclusive option 4 years 1 month ago #48294

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4272
  • Thank you received: 806
  • Karma: 369
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re:Array filter with exclusive option 4 years 1 month ago #48307

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5331
  • Thank you received: 296
  • Karma: 249
Thanks for clarifying!

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Re:Array filter with exclusive option 4 years 1 month ago #48311

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: 4 years 1 month ago by wireframemedia.
The administrator has disabled public write access.

Re:Array filter with exclusive option 4 years 1 month ago #48321

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4272
  • Thank you received: 806
  • Karma: 369
...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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re:Array filter with exclusive option 4 years 1 month ago #48322

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: 4 years 1 month ago by wireframemedia.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.188 seconds
Donation Image