Array filter with exclusive option

Plus d'informations
il y a 7 ans 3 mois #48271 par wireframemedia
wireframemedia a créé le sujet : Array filter with exclusive option
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.

Connexion pour participer à la conversation.

Plus d'informations
il y a 7 ans 3 mois #48280 par tpartner
tpartner a répondu au sujet : 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.

Connexion pour participer à la conversation.

Plus d'informations
il y a 7 ans 3 mois #48281 par wireframemedia
wireframemedia a répondu au sujet : 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

Connexion pour participer à la conversation.

Plus d'informations
il y a 7 ans 3 mois #48282 par tpartner
tpartner a répondu au sujet : 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.
<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.

Connexion pour participer à la conversation.

Plus d'informations
il y a 7 ans 3 mois #48291 par Mazi
Mazi a répondu au sujet : 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
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Connexion pour participer à la conversation.

Plus d'informations
il y a 7 ans 3 mois #48294 par tpartner
tpartner a répondu au sujet : 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.

Connexion pour participer à la conversation.

Plus d'informations
il y a 7 ans 3 mois #48307 par Mazi
Mazi a répondu au sujet : Array filter with exclusive option
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)survey-consulting.com'"

Connexion pour participer à la conversation.

Plus d'informations
il y a 7 ans 3 mois - il y a 7 ans 3 mois #48311 par wireframemedia
wireframemedia a répondu au sujet : 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
Dernière édition: il y a 7 ans 3 mois par wireframemedia.

Connexion pour participer à la conversation.

Plus d'informations
il y a 7 ans 3 mois #48321 par tpartner
tpartner a répondu au sujet : 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.

Connexion pour participer à la conversation.

Plus d'informations
il y a 7 ans 3 mois - il y a 7 ans 3 mois #48322 par wireframemedia
wireframemedia a répondu au sujet : 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.
Dernière édition: il y a 7 ans 3 mois par wireframemedia.

Connexion pour participer à la conversation.

Plus d'informations
il y a 7 ans 3 mois #48323 par Mazi
Mazi a répondu au sujet : 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
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Connexion pour participer à la conversation.

Plus d'informations
il y a 7 ans 3 mois #48350 par tpartner
tpartner a répondu au sujet : 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.
Pièces jointes :

Connexion pour participer à la conversation.

Plus d'informations
il y a 7 ans 3 mois #48351 par wireframemedia
wireframemedia a répondu au sujet : Array filter with exclusive option
Sorry, perhaps I didn't word that correctly.

The survey has a series of questions (multi-choice, checkboxes) which all cascade, feed to one another. The final one also needs a static/exclusive option. As below:

Q1
What colors do you like?
[ ] Red
[ ] Blue
[ ] Green
[ ] Yellow

Q2
Which colors do you like best? (feeds only the answers chosen in Q1)
[ ] Red
[ ] Blue
* This being the final question in the series also needs one other static choice not present in Q1/array filter.
[ ] None of the above

This is what they are trying to achieve.
Does that help?

Thank you again.
Dawna

Connexion pour participer à la conversation.

Plus d'informations
il y a 7 ans 3 mois #48353 par tpartner
tpartner a répondu au sujet : Array filter with exclusive option
Okay, I see now. I thought you were trying to filter an array type with a multi-option type (as in the image above). Now what I'm seeing is a series of multi-options filtering each other and culminating in a final one that has a static option.

I'll have to give it a little more thought and see how the "automatic filtering" will affect our "custom filter" on the last two in the cascade.

How many questions are there in the cascade?

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

Connexion pour participer à la conversation.

Plus d'informations
il y a 7 ans 3 mois #48356 par wireframemedia
wireframemedia a répondu au sujet : Array filter with exclusive option
Tony,

It's only a set of three questions which cascade, each however has 13 options/choices and the last needs to have the "none of the above" static option.

However, later in the survey, the results of that last one are piped back in repeatedly in the question text (which works great), and used for skip rules (conditions, again works great).

I am highly impressed by this product and am advising my clients to start using it and donate to support the efforts.

This survey is a highly complex one and just about 98% of it was easily accomplished through LimeSurvey, out-of-the-box. I have only a few straggling issues.

Thank you for all your help with this.
Dawna

Connexion pour participer à la conversation.

Commencez dès maintenant !

Créez simplement un compte et commencez à utiliser LimeSurvey dès aujourd'hui.

Inscrivez-vous maintenant

Inscrivez-vous à notre Newsletter!