- Posts: 1
- Thank you received: 1
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Create a question with multi array (1-5)
- gabrielet
- Topic Author
- Offline
- New Member
Less
More
10 years 9 months ago #98390
by gabrielet
Create a question with multi array (1-5) was created by gabrielet
Hi to all,
is a little bit i didn't write on this forum. How are you?
I'd like to create a particular questionon limesurvey like this:
Question
Bablblblbllblblblblblblblbllb ?
ORGANIZATION |1 - 2| - 3| - 4| - 5
organization bureau | | | |
Visiting and exctiments | | | |
Partecipation | | | |
JOBS DESK
Utility of the course | | | |
Time for project | | | |
This only an example. A question that have multi paragraph and group of response.
I dont want to create for question one for a paragraph...
Suggestions?
Thanks
Gabriele
is a little bit i didn't write on this forum. How are you?
I'd like to create a particular questionon limesurvey like this:
Question
Bablblblbllblblblblblblblbllb ?
ORGANIZATION |1 - 2| - 3| - 4| - 5
organization bureau | | | |
Visiting and exctiments | | | |
Partecipation | | | |
JOBS DESK
Utility of the course | | | |
Time for project | | | |
This only an example. A question that have multi paragraph and group of response.
I dont want to create for question one for a paragraph...
Suggestions?
Thanks
Gabriele
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
10 years 9 months ago - 10 years 9 months ago #98402
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 Create a question with multi array (1-5)
There is no built-in provision to add sub-headings to arrays but you can do it with a little JavaScript.
Add the following to the end of template.js:
And, then to insert a subheading in row 3 of the array, add something like this to the question source. Replace the row number (3) and the text (SUBHEADING 1) as necessary
Add the following to the end of template.js:
Code:
function insertSubHeading(qID, rowNum, text) { var thisQuestion = $('#question'+qID+''); var cols = $('table.subquestions-list thead td, table.subquestions-list thead th', thisQuestion).length; $('#question'+qID+' table.subquestions-list tbody tr:eq('+(rowNum-2)+')').after('<tr class="subHeading"><th class="answertext">'+text+'</th><td colspan="'+(cols-1)+'"></td></tr>'); }
And, then to insert a subheading in row 3 of the array, add something like this to the question source. Replace the row number (3) and the text (SUBHEADING 1) as necessary
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ insertSubHeading('{QID}', 3, 'SUBHEADING 1'); }); </script>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 10 years 9 months ago by tpartner.
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13647
- Thank you received: 2491
10 years 9 months ago - 10 years 9 months ago #98410
by DenisChenu
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic Create a question with multi array (1-5)
Hello,
A solution i use sometimes:
If question is not mandatory (but have solution for this too).
Add for subheading in sub question
And in js:
In css:
Denis
A solution i use sometimes:
If question is not mandatory (but have solution for this too).
Add for subheading in sub question
Code:
<strong>My sub heading</strong>
And in js:
Code:
$("table.question tbody th > strong").each(function(){ $(this).closest("tr").addClass("sub-heading"); }
In css:
Code:
.sub-heading input{display:none} .sub-heading{background:#ccc}
Denis
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Last edit: 10 years 9 months ago by DenisChenu.
The topic has been locked.
- keunes
- Offline
- Junior Member
Less
More
- Posts: 29
- Thank you received: 2
7 years 11 months ago #135341
by keunes
Replied by keunes on topic Create a question with multi array (1-5)
Neither option seems to work in Version 2.50+ Build 160425
Are there any changes to the code needed, or other suggestions?
Are there any changes to the code needed, or other suggestions?
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
7 years 11 months ago #135352
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 Create a question with multi array (1-5)
Try this:
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // Call the function insertSubHeading('{QID}', 3, 'SUBHEADING 1'); }); function insertSubHeading(qID, rowNum, text) { // Identify some stuff var thisQuestion = $('#question'+qID+''); var cols = $('table.subquestion-list thead tr:eq(0) > *', thisQuestion).length; // Insert the new row $('#question'+qID+' table.subquestion-list tbody tr:eq('+(rowNum-1)+')').before('<tr class="subHeading"><th class="answertext">'+text+'</th><td colspan="'+(cols-1)+'"></td></tr>'); // Fix up the row classes var rowClass = 1; $('table.subquestion-list tbody tr', thisQuestion).each(function(i) { if($(this).hasClass('subHeading')) { rowClass = 1 } else { rowClass++; $(this).removeClass('array1 array2') if(rowClass % 2 == 0) { $(this).addClass('array2'); } else { $(this).addClass('array1'); } } }); } </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.
- keunes
- Offline
- Junior Member
Less
More
- Posts: 29
- Thank you received: 2
7 years 11 months ago #135378
by keunes
Replied by keunes on topic Create a question with multi array (1-5)
Thanks again for the quick reply!
Adding this to the question field doesn't work; the code gets removed upon saving it seems.
I changed the following:
Is there anything that I need to differently?
Adding this to the question field doesn't work; the code gets removed upon saving it seems.
I changed the following:
Code:
insertSubHeading('{QID}', 1, 'Traditionele media'); insertSubHeading('{QID}', 4, 'Digi media');
Is there anything that I need to differently?
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
7 years 11 months ago #135379
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 Create a question with multi array (1-5)
That should work assuming
your survey is set up to use 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.
- keunes
- Offline
- Junior Member
Less
More
- Posts: 29
- Thank you received: 2
7 years 11 months ago #135382
by keunes
Replied by keunes on topic Create a question with multi array (1-5)
Yup, sorry, I didn't check my question preview properly. Tried to delete my answer from the forum but that didn't work.
So it does seem to work indeed, although the code does seem to get removed upon re-editing the question (it's not visible in when using 'Source' and after saving again the subheadings are removed indeed from the preview).
In any case I can get it working
To add a dash of colour to the subheadings I can add the following to my css file, right?
So it does seem to work indeed, although the code does seem to get removed upon re-editing the question (it's not visible in when using 'Source' and after saving again the subheadings are removed indeed from the preview).
In any case I can get it working
To add a dash of colour to the subheadings I can add the following to my css file, right?
Code:
tr.Subheading { background-color: purple; color: #ffffff; }
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
7 years 11 months ago #135384
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 Create a question with multi array (1-5)
Bug here - www.limesurvey.org/forum/design-issues/1...rce-code-not-visibleSo it does seem to work indeed, although the code does seem to get removed upon re-editing the question (it's not visible in when using 'Source' and after saving again the subheadings are removed indeed from the preview).
Yes, if you like purple.To add a dash of colour to the subheadings I can add the following to my css file, right?
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: keunes
The topic has been locked.
- keunes
- Offline
- Junior Member
Less
More
- Posts: 29
- Thank you received: 2
7 years 11 months ago - 7 years 11 months ago #135388
by keunes
Replied by keunes on topic Create a question with multi array (1-5)
I think I prefer the blue of the standard template
Last comment for other users: I updated the code so that the heading will span across the table (ie: added colspan to th, removed td, right after the "// Insert the new row")
And added the following to "css/flat_and_modern.css" (based on default template of v. 2.5):
Last comment for other users: I updated the code so that the heading will span across the table (ie: added colspan to th, removed td, right after the "// Insert the new row")
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // Call the function insertSubHeading('{QID}', 1, 'Traditionele platformen'); insertSubHeading('{QID}', 8, 'Digitale platformen die niet horen bij bovenstaande &#39;traditionele media&#39;'); }); function insertSubHeading(qID, rowNum, text) { // Identify some stuff var thisQuestion = $('#question'+qID+''); var cols = $('table.subquestion-list thead tr:eq(0) > *', thisQuestion).length; // Insert the new row $('#question'+qID+' table.subquestion-list tbody tr:eq('+(rowNum-1)+')').before('<tr class="subHeading"><th class="answertext subHeading" colspan="'+(cols)+'">'+text+'</th></tr>'); // Fix up the row classes var rowClass = 1; $('table.subquestion-list tbody tr', thisQuestion).each(function(i) { if($(this).hasClass('subHeading')) { rowClass = 1 } else { rowClass++; $(this).removeClass('array1 array2') if(rowClass % 2 == 0) { $(this).addClass('array2'); } else { $(this).addClass('array1'); } } }); } </script>
And added the following to "css/flat_and_modern.css" (based on default template of v. 2.5):
Code:
/* Array table Subheading*/ .subHeading { background-color: #233140; color: #ffffff; font-weight: normal; padding-top: 1em !important; }
Last edit: 7 years 11 months ago by keunes. Reason: apply code style
The following user(s) said Thank You: tpartner
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
7 years 11 months ago #135389
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 Create a question with multi array (1-5)
Thanks, I like it when people take my suggestions and modify them for their specific needs. That's why I heavily comment most of my posted code.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.