- Posts: 15
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Array filter with exclusive option
- wireframemedia
- Topic Author
- Offline
- New Member
Less
More
13 years 7 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.
Thank you.
d.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3593
13 years 7 months ago #48280
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
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.
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
- Topic Author
- Offline
- New Member
Less
More
- Posts: 15
- Thank you received: 0
13 years 7 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
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3593
13 years 7 months ago #48282
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
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.
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
- Offline
- Official LimeSurvey Partner
13 years 7 months ago #48291
by Mazi
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
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?
Will it not be listed at all when using array filter?
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3593
13 years 7 months ago #48294
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
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
- Offline
- Official LimeSurvey Partner
13 years 7 months ago #48307
by Mazi
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
Replied by Mazi on topic Array filter with exclusive option
Thanks for clarifying!
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.
- wireframemedia
- Topic Author
- Offline
- New Member
Less
More
- Posts: 15
- Thank you received: 0
13 years 7 months ago - 13 years 7 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
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: 13 years 7 months ago by wireframemedia.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3593
13 years 7 months ago #48321
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Array filter with exclusive option
Did you disable the array filter in the advance settings for the array question?...the exclusive option is still not showing up...
I'll have to look into that tonight.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.
The script is designed for a multi-options (checkbox) followed by an array (radio buttons) question.I have to use checkboxes (not radio buttons) for multiple responses
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
- Topic Author
- Offline
- New Member
Less
More
- Posts: 15
- Thank you received: 0
13 years 7 months ago - 13 years 7 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.
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: 13 years 7 months ago by wireframemedia.
The topic has been locked.
- Mazi
- Offline
- Official LimeSurvey Partner
13 years 7 months ago #48323
by Mazi
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
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
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3593
13 years 7 months ago #48350
by tpartner
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.
Replied by tpartner on topic Array filter with exclusive option
Hmm...now I'm a little confused. I thought you were filtering an array with a multiple options question (see my screenshot).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...
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.
Attachments:
The topic has been locked.