- Posts: 18
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Having groups of options in multiple choices
- mresibois
- Topic Author
- Offline
- New Member
Less
More
4 years 3 months ago #192272
by mresibois
Having groups of options in multiple choices was created by mresibois
Dear helpers,
I have another question. My survey is almost ready but could be visually improved.
Context : following help recieved on this very forum , I have a question A where I list a lot of projects. People have to check the ones they know of. Question B is about whether they attended the projects they know (checked at A) and question D is an array where they assess the satisfaction about projects they attended (checked at B ).
The solution given previously works perfectly, but I had to make question A (and others) looking like this :
Fruits - Apple []
Fruits - Banana []
Fruits - Strawberry []
Vegetables - Onions []
Vegetables - carrots []
And what I would like, if possible, is :
Fruits
- Apple []
- Banana []
- Strawberry []
Vegegatbles
- Onions []
- Carrots []
One idea I had was to use html/css, like this :
Fruits<br />- Apple []
- Banana []
- Strawberry []
Vegetables<br />- Onions []
- Carrots []
But this does not work as people may select only one suboption that may not be te first one (e.g., only Banana and Carrots).
Is there any way to create such option categories (the equivalent of the optgroup tag in a select tag) ??
I have another question. My survey is almost ready but could be visually improved.
Context : following help recieved on this very forum , I have a question A where I list a lot of projects. People have to check the ones they know of. Question B is about whether they attended the projects they know (checked at A) and question D is an array where they assess the satisfaction about projects they attended (checked at B ).
The solution given previously works perfectly, but I had to make question A (and others) looking like this :
Fruits - Apple []
Fruits - Banana []
Fruits - Strawberry []
Vegetables - Onions []
Vegetables - carrots []
And what I would like, if possible, is :
Fruits
- Apple []
- Banana []
- Strawberry []
Vegegatbles
- Onions []
- Carrots []
One idea I had was to use html/css, like this :
Fruits<br />- Apple []
- Banana []
- Strawberry []
Vegetables<br />- Onions []
- Carrots []
But this does not work as people may select only one suboption that may not be te first one (e.g., only Banana and Carrots).
Is there any way to create such option categories (the equivalent of the optgroup tag in a select tag) ??
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
4 years 3 months ago #192274
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 Having groups of options in multiple choices
You can use CSS and JavaScript to remove the checkboxes in the "heading" rows.
Have a look at this post - www.limesurvey.org/forum/can-i-do-this-w...ents?start=15#190293
Have a look at this post - www.limesurvey.org/forum/can-i-do-this-w...ents?start=15#190293
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: mresibois
The topic has been locked.
- mresibois
- Topic Author
- Offline
- New Member
Less
More
- Posts: 18
- Thank you received: 0
4 years 3 months ago #192275
by mresibois
Replied by mresibois on topic Having groups of options in multiple choices
Thanks (as usual) !
It seems all right for question A, but then how to be sure that no category will be shown on question B in case nothing is selected (let's say no one selected any fruit, I do not want the category "fruit" to appear empty on the next question)
It seems all right for question A, but then how to be sure that no category will be shown on question B in case nothing is selected (let's say no one selected any fruit, I do not want the category "fruit" to appear empty on the next question)
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12881
- Thank you received: 3965
4 years 3 months ago - 4 years 3 months ago #192276
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Having groups of options in multiple choices
You would like something like this?
Here's a script
And for the multiple question this?
Here's a script
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify this question var thisQuestion = $('#question{QID}'); // Define the sub-heading text strings var subHeading1 = 'Fruits'; var subHeading2 = 'Vegetables'; var columnsLength = $('tr.answers-list:eq(0) > *', thisQuestion).length; // Insert the new rows $('tr.answers-list:eq(0)', thisQuestion).before('<tr class="sub-header-row"><th colspan="'+columnsLength+'">'+subHeading1+'</th></tr>'); $('tr.answers-list:eq(3)', thisQuestion).before('<tr class="sub-header-row"><th colspan="'+columnsLength+'">'+subHeading2+'</th></tr>'); // Fix up the row classes var rowClass = 1; $('table.subquestions-list tbody tr', thisQuestion).each(function(i) { if($(this).hasClass('sub-header-row')) { rowClass = 1 } else { rowClass++; $(this).removeClass('array1 array2') if(rowClass % 2 == 0) { $(this).addClass('array2'); } else { $(this).addClass('array1'); } } }); }); </script> <style type="text/css">.sub-header-row { margin-bottom: 20px; } .sub-header-row th { background-color: #efefef; color: #000000 !important; text-align: left; } </style>
And for the multiple question this?
Code:
<script charset="utf-8" type="text/javascript"> $(document).ready(function() { $( '#question{QID} .question-item:eq(0)').addClass('hide-pseudo-elements').find('input.checkbox').remove(); $( '#question{QID} .question-item:eq(4)').addClass('hide-pseudo-elements').find('input.checkbox').remove(); $( '#question{QID} .question-item:eq(0)').addClass('hide-pseudo-elements').find('.comment-container').remove(); $( '#question{QID} .question-item:eq(4)').addClass('hide-pseudo-elements').find('.comment-container').remove(); }); </script> <style type="text/css">.hide-pseudo-elements label::before, .hide-pseudo-elements label::after { display: none; } .hide-pseudo-elements .label-text { margin-left: -20px; } </style>
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 4 years 3 months ago by Joffm.
The following user(s) said Thank You: mresibois
The topic has been locked.
- mresibois
- Topic Author
- Offline
- New Member
Less
More
- Posts: 18
- Thank you received: 0
4 years 3 months ago #192277
by mresibois
Replied by mresibois on topic Having groups of options in multiple choices
It looks like an elegant solution (not totally familiar with Boodstrap). Am I correct in thinking that this is then based on the class of the suboptions ? Then I would have to write, for each subquestion :
<span class="Fruits">Apple []</span>
<span class="Fruits">Banana []</span>
<span class="Fruits"> Strawberry []</span>
<span class="Vegetables">Onions []</span>
<span class="Vegetables">Carrots []</span>
So that if only one option is taken, for the next question, the script will add it just above that one option (no matter whether that was the first one or not), and that if no subheading is present (i.e., respondent did not select anything from that category) nothing appears ?
<span class="Fruits">Apple []</span>
<span class="Fruits">Banana []</span>
<span class="Fruits"> Strawberry []</span>
<span class="Vegetables">Onions []</span>
<span class="Vegetables">Carrots []</span>
So that if only one option is taken, for the next question, the script will add it just above that one option (no matter whether that was the first one or not), and that if no subheading is present (i.e., respondent did not select anything from that category) nothing appears ?
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
4 years 3 months ago - 4 years 3 months ago #192281
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 Having groups of options in multiple choices
Use sub-question relevance instead of array-filter to hide/show the rows in question B.but then how to be sure that no category will be shown on question B in case nothing is selected (let's say no one selected any fruit, I do not want the category "fruit" to appear empty on the next question)
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 4 years 3 months ago by tpartner.
The following user(s) said Thank You: mresibois
The topic has been locked.
- mresibois
- Topic Author
- Offline
- New Member
Less
More
- Posts: 18
- Thank you received: 0
4 years 3 months ago #192282
by mresibois
Replied by mresibois on topic Having groups of options in multiple choices
In this case, may I use several conditions, something like:
!is_empty(Q1_SQ001)&&!is_empty(Q1_SQ002)
?
!is_empty(Q1_SQ001)&&!is_empty(Q1_SQ002)
?
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
4 years 3 months ago - 4 years 3 months ago #192283
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 Having groups of options in multiple choices
Yes, several for the heading rows, but I think you need OR, not AND.
Code:
!is_empty(Q1_SQ002) OR !is_empty(Q1_SQ003) OR !is_empty(Q1_SQ004)
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 4 years 3 months ago by tpartner.
The following user(s) said Thank You: mresibois
The topic has been locked.
- mresibois
- Topic Author
- Offline
- New Member
Less
More
- Posts: 18
- Thank you received: 0
4 years 3 months ago #192284
by mresibois
Replied by mresibois on topic Having groups of options in multiple choices
All right, as last time thanks a million time for both your help! I think I should be able to achieve what I'd like to (otherwise I'll come back).
Best,
Maxime
Best,
Maxime
The topic has been locked.