Welcome to the LimeSurvey Community Forum

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

Disable specific boxes (=answer options) in a array question (numbers)

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 1 month ago #181236 by tpartner
It's not a good idea to use the same question codes for the x and y axes - it leads to confusion when trying to identify elements. For this example, I have recoded the Q1 answers (x-axis) to A1-A4.

Rather than hiding the elements, you should remove them so they cannot be selected via the keyboard.

In your example, add something like this to the question source:

Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).ready(function() {
 
    // Remove row 1, answer "A3"
    $('#question{QID} tr.answers-list:eq(0) input:radio[value="A3"]').nextAll('label').remove();
    $('#question{QID} tr.answers-list:eq(0) input:radio[value="A3"]').remove();
 
    // Remove row 1, answer "A4"
    $('#question{QID} tr.answers-list:eq(0) input:radio[value="A4"]').nextAll('label').remove();
    $('#question{QID} tr.answers-list:eq(0) input:radio[value="A4"]').remove();
 
    // Remove row 2, answer "A3"
    $('#question{QID} tr.answers-list:eq(1) input:radio[value="A3"]').nextAll('label').remove();
    $('#question{QID} tr.answers-list:eq(1) input:radio[value="A3"]').remove();
 
    // Remove row 2, answer "A4"
    $('#question{QID} tr.answers-list:eq(1) input:radio[value="A4"]').nextAll('label').remove();
    $('#question{QID} tr.answers-list:eq(1) input:radio[value="A4"]').remove();
  });  
</script>



Sample survey attached:

File Attachment:

File Name: limesurvey...5951.lss
File Size:27 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
5 years 1 month ago #181239 by mcovents
Super!
This is what we were looking for.
Best regards,
Marc
The topic has been locked.
More
5 years 1 month ago #181247 by mcovents
Dear Tony,

Can we ask you another question in the same area?

Do you also have a suggestion how we could remove some input fields in text (and number) arrays in the 3.15 version?

We used this type of question in another survey in which teachers have to indicate when they are available and when not for 6 days of the week (monday-saturday) for three time slots (morning, afternoon and evening).

More specific we used a text array question (example 1 in the attached file), which we further elaborated with a javascript so that they could select their responses from drop down lists (example 2 in attach).

However some of the options are redundant as our school is closed on friday evening as well as on saturday afternoon and evening.

the example is a bit comparable to the example given on

manual.limesurvey.org/Workarounds:_Manip...ation_LS_Version_3.x :

Disable or hide selected fields in a matrix question

We were able to disable options in example 1, but not to remove them. However when we put the extra javascript on it (example 2), also the disable did not work anymore....


As we did not find a sollution to remove those fields we added an extra option "there is no class". It would however be more userfriendly if we could remove the unnecessary fields...


Suggestions would be very welcome, as well for the less complex text (example1) and numer arrays as for the more complex one (example 2)...

Thanks in advance

Marc.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 1 month ago #181270 by tpartner
The solution is the same for both question types.

So, in your sample survey, to remove row 5 x-axis code "av", row 6 x-axis code "nm" and row 6 x-axis code "av", add this to the question source:

Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).ready(function() {
 
    // Remove row 5, x-axis code "av"
    $('#question{QID} tr.subquestion-list:eq(4) .answer_cell_av *').remove();
 
    // Remove row 6, x-axis code "nm"
    $('#question{QID} tr.subquestion-list:eq(5) .answer_cell_nm *').remove();
 
    // Remove row 6, x-axis code "av"
    $('#question{QID} tr.subquestion-list:eq(5) .answer_cell_av *').remove();
  });  
</script>



Sample survey attached:

File Attachment:

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

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
5 years 1 month ago #181279 by mcovents
Thanks again for your fast reply.
Works perfect!
Best regards,
Marc.
The topic has been locked.
More
4 years 2 weeks ago #196667 by zserban
Hi, tpartner,

I am wondering how to hide an answer option (like, does not apply) for an array where subquestions are randomly displayed. Hiding row X for answer 6, for instance, won't help. How to hook the logic to the subquestions, rather than a row number?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 2 weeks ago #196691 by tpartner
Can you please provide a screenshot/mockup and a small sample survey (.lss file) containing only the relevant question?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: zserban
The topic has been locked.
More
4 years 2 weeks ago #196706 by zserban

tpartner wrote: Can you please provide a screenshot/mockup and a small sample survey (.lss file) containing only the relevant question?



Hi tpartner, thank you for taking the time!

I inserted the code I found here in the array question.

It does the job (hiding the row 4 and 12 for answer 6. These rows correspond to subquestions 4 and 12, which shouldn't be answered by option 6.), but the random - which is a must - is messing it up.
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 2 weeks ago #196719 by holch
Any specific reason why you zipped the LSS file?

You can upload it directly to the forum. One step less for Tpartner to help you.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The following user(s) said Thank You: zserban
The topic has been locked.
More
4 years 2 weeks ago #196721 by zserban
Oh, out of habbit.


Also, forgot to mention, is Limesurvey 3 branch (the latest public release)
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 2 weeks ago - 4 years 2 weeks ago #196740 by tpartner
You can target the rows with the sub-question codes like this:

Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).ready(function() {
 
    // Remove row 4, answer "6"
    $('#question{QID} tr.answers-list[id$="X{QID}4"] input:radio[value="6"]').nextAll('label').remove();
    $('#question{QID} tr.answers-list[id$="X{QID}4"] input:radio[value="6"]').remove();
 
    // Remove row 12, answer "6"
    $('#question{QID} tr.answers-list[id$="X{QID}12"] input:radio[value="6"]').nextAll('label').remove();
    $('#question{QID} tr.answers-list[id$="X{QID}12"] input:radio[value="6"]').remove();
  });  
</script>

This part of the selector - tr.answers-list[id$="X{QID}12"] - effectively says "row with ID ending in X + Question ID + SQ Code 12".

Sample survey attached:

File Attachment:

File Name: limesurvey...4431.lss
File Size:47 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 4 years 2 weeks ago by tpartner.
The following user(s) said Thank You: zserban
The topic has been locked.
More
4 years 2 weeks ago #196744 by zserban

tpartner wrote: You can target the rows with the sub-question codes like this:

Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).ready(function() {
 
    // Remove row 4, answer "6"
    $('#question{QID} tr.answers-list[id$="X{QID}4"] input:radio[value="6"]').nextAll('label').remove();
    $('#question{QID} tr.answers-list[id$="X{QID}4"] input:radio[value="6"]').remove();
 
    // Remove row 12, answer "6"
    $('#question{QID} tr.answers-list[id$="X{QID}12"] input:radio[value="6"]').nextAll('label').remove();
    $('#question{QID} tr.answers-list[id$="X{QID}12"] input:radio[value="6"]').remove();
  });  
</script>

This part of the selector - tr.answers-list[id$="X{QID}12"] - effectively says "row with ID ending in X + Question ID + SQ Code 12".

Sample survey attached:

File Attachment:

File Name: limesurvey...4431.lss
File Size:47 KB



It works very well! I really appreciate it (and others will do too), tpartner.

No doubt, in a similar fashion, you can even filter available answers by responses given at previous questions, something that cannot be done out of the box. This might be quite handy because it could shorten the total number of questions a respondent has to answer.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose