Welcome to the LimeSurvey Community Forum

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

Filter 2nd column dropdown answer in array based on 1st column answer

  • adilar39
  • adilar39's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
11 months 2 weeks ago - 11 months 2 weeks ago #243223 by adilar39
Please help us help you and fill where relevant:
Your LimeSurvey version: 3.25.18
Own server or LimeSurvey hosting: own
Survey theme/template: fruity
==================
Hello all, I would like to ask something.

I've made an array question that based on this answer:
forums.limesurvey.org/index.php/forum/de...ew-answer-row#216657

In that example, the 4th column can only be answered if 2nd column is answered "Yes".
I want to apply something like that, but with two choices that can proceed to answer the next column, and because the answers is a lot, I want so that the dropdown have a searchable feature like this custom question theme:
github.com/tpartner/LimeSurvey-Searchable-Dropdown-3x-5x

I've seen searchable dropdown from this forum too:
forums.limesurvey.org/forum/can-i-do-thi...ropdown-autocomplete
If the github example one is hard to be applied, this one is good too.

Example:
If I choose "Bus" in 1st column, I want the 2nd column to have answer list: 1A, 2B, 3C, 4D, and 5E only.
If I choose "Minibus" in 1st column, I want the 2nd column to have answer list: 6F, 7G, 8H, 9I, and 10J only.

Image and survey attached. Thanks in advance.
Last edit: 11 months 2 weeks ago by adilar39. Reason: typo

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 months 2 weeks ago #243228 by Joffm
Hi,
in my opinion the easiest solution is to use two columns for "Bus" and "Minibus"
 

By the way:
There was an error in your script
"Returning to page" (only this)
Code:
        // Returning to page
    $('.with-select input:text', thisQuestion).each(function(i) {
      var thisCell = $(this).closest('.answer-item');
      var inputText = $.trim($(this).val());
      $('select.inserted-select', thisCell).val(inputText);
    });

And if you use "varLengthArray" with these drop-downs you have to handle them after "remove row"
Just one line to add in "removeRow"
Code:
            function removeRow(qID) {
                var arrayRow = '#question' + qID + ' table.ls-answers tr.subquestion-list';
                var rowCount = $( arrayRow ).size() - 1;
                $( arrayRow + '[name="visible"]:last input[type="text"]' ).val('');
                $( arrayRow + '[name="visible"]:last select' ).val('');   // This is added
                $( arrayRow + '[name="visible"]:last' ).attr('name', 'hidden').hide();
                $( 'div#addButton'+qID ).show();
                if ( $( arrayRow + ':eq(1)' ).attr('name') == 'hidden' )  {
                    $( 'div#removeButton'+qID ).hide();
                }
            }

And you can do the same with an "autocomplete"
 

and because the answers is a lot,

At the moment I do not see this. So I think your example is not realistic.

Joffm




 

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

Please Log in to join the conversation.

  • adilar39
  • adilar39's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
11 months 2 weeks ago #243239 by adilar39
Thank you for the answer Joffm.

Now that you explain it, making it as two column looks better rather than one. And it's easier to see when exporting the responses. Thanks, I've managed to make it too.

And thank you for correcting the mistakes in the code.

With the autocomplete question, at the time I made the question, the person who asked me to make the survey still haven't made the answer list, so i just put some examples. Now they already showed me the answer list, and it contains 143 answers for "Bus" column, and 82 answers for "Minibus" column.
I'm still struggling with the autocomplete one. I thought i just need to copy this code into the source code, but i don't know where to put it:
  forums.limesurvey.org/index.php/forum/ca...lete?start=24#211223
When i put it in what supposed to be answer list (1A, 2B, 3C, 4D, 5E), it turns everything into text input like the image i attached.
How can you make that autocomplete works?

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 months 2 weeks ago #243240 by Joffm
No,
it is a different script.
One for the dropdown in the first column and the other one for the dropdown.

Later I'll send a sample survey.

Joffm

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

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 months 2 weeks ago - 11 months 2 weeks ago #243253 by Joffm
Here the promised sample survey.
 

File Attachment:

File Name: limesurvey...1661.lss
File Size:30 KB



Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 11 months 2 weeks ago by Joffm.
The following user(s) said Thank You: adilar39

Please Log in to join the conversation.

  • adilar39
  • adilar39's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
11 months 2 weeks ago - 11 months 2 weeks ago #243262 by adilar39
It works, thank you so much Joffm.

I now want to count the array that has answered by participant. Using equation question type with {count(that.A1)} in equation fields, it can count and showed the number of answered array. But it count every array answered like the image attached.
Is there anyway so that the number shown only counted from the 1st column (Vehicle name)?
I've tried to change the equation into {count(that.A1_1 == "1" or that.A1_2 == "2")}, but it doesn't work.
Last edit: 11 months 2 weeks ago by adilar39. Reason: wrong naming

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 months 2 weeks ago - 11 months 2 weeks ago #243266 by Joffm
-

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 11 months 2 weeks ago by Joffm.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 months 2 weeks ago #243267 by Joffm
function "countifop"

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

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose