- Posts: 3
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Need help with dual Array with question in the middle...
- TerryInLeesburg
- Topic Author
- Offline
- New Member
Less
More
6 years 10 months ago #156121
by TerryInLeesburg
Need help with dual Array with question in the middle... was created by TerryInLeesburg
We are trying to create a question like the attached picture.
I can get the dual scales, but is there a way to put the actual question in the "middle"?
I can get the dual scales, but is there a way to put the actual question in the "middle"?
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10115
- Thank you received: 3597
6 years 10 months ago #156133
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 Need help with dual Array with question in the middle...
What LimeSurvey version are you using?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- TerryInLeesburg
- Topic Author
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
6 years 10 months ago #156149
by TerryInLeesburg
Replied by TerryInLeesburg on topic Need help with dual Array with question in the middle...
2.5.4
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10115
- Thank you received: 3597
6 years 10 months ago #156150
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 Need help with dual Array with question in the middle...
Set up your survey to use JavaScript
and place the following script in the source of the question:
Sample survey attached:
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // Identify this question var qID = {QID}; var thisQuestion = $('#question'+qID); // Remove LS imposed column widths $('colgroup', thisQuestion).remove(); // Move the table cells $('table.subquestion-list thead tr', thisQuestion).each(function(i, thisRow) { $('td.header_separator', thisRow).after($('th.header_answer_text', thisRow)).remove(); }); $('tr.answers-list', thisQuestion).each(function(i, thisRow) { $('td.dual_scale_separator', thisRow).after($('th.answertext', thisRow)).remove(); }); // Insert the center header label var centerHeader = 'Learning Methods'; $('table.subquestion-list thead tr:eq(0) th.header_answer_text', thisQuestion).text(centerHeader); // Insert some clean-up styles (could be placed in template.css) $('<style type="text/css">\ #question'+qID+' th.header_answer_text, #question'+qID+' th.answertext {\ width:50%;\ text-align:center;\ hyphens: none;\ overflow-wrap: normal;\ }\ #question'+qID+' td.radio-item {\ padding: 10px;\ }\ #question'+qID+' .radio label::before, #question'+qID+' .radio label::after {\ margin-left: 0;\ }\ @media only screen and (max-width: 801px) {\ #question'+qID+' th.answertext {\ clear: both;\ text-align: left;\ }\ #question'+qID+' td.radio-item {\ float: left;\ width: auto !important;\ }\ }\ </style>').appendTo( "head" ) }); </script>
Sample survey attached:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The following user(s) said Thank You: TerryInLeesburg
The topic has been locked.
- VAMOS_FHB
- Offline
- New Member
Less
More
- Posts: 7
- Thank you received: 0
6 years 3 months ago - 6 years 3 months ago #162634
by VAMOS_FHB
Replied by VAMOS_FHB on topic Need help with dual Array with question in the middle...
For me, this does not work as it should (see attached screenshot) in LS 3.0.4
Attachments:
Last edit: 6 years 3 months ago by VAMOS_FHB.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10115
- Thank you received: 3597
6 years 3 months ago - 6 years 3 months ago #162635
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 Need help with dual Array with question in the middle...
That looks like a template problem.
This workaround is for the 2.7.x versions. What template are you using?
This workaround is for the 2.7.x versions. What template are you using?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 6 years 3 months ago by tpartner.
The topic has been locked.
- VAMOS_FHB
- Offline
- New Member
Less
More
- Posts: 7
- Thank you received: 0
6 years 3 weeks ago #166997
by VAMOS_FHB
Replied by VAMOS_FHB on topic Need help with dual Array with question in the middle...
I successfully have used this workaround in a survey. In another survey I'd now like to use the expression manager for conditional wording in the answers. This works fine with the normal array dual scale. But when using the tpartner's code, the expression inside the {} is no longer recongized. Is there a solution for that? LS version is 2.73.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10115
- Thank you received: 3597
6 years 3 weeks ago #167016
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 Need help with dual Array with question in the middle...
I see nothing in the script that should affect Expression Manager. Can you attach a small sample survey?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- VAMOS_FHB
- Offline
- New Member
Less
More
- Posts: 7
- Thank you received: 0
6 years 3 weeks ago #167028
by VAMOS_FHB
Replied by VAMOS_FHB on topic Need help with dual Array with question in the middle...
Attached you'll find an example. Thank you!
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10115
- Thank you received: 3597
6 years 3 weeks ago #167045
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 Need help with dual Array with question in the middle...
It seems to be a bug in Expression Manager. The perfectly valid JavaScript syntax for the styles is preventing EM from parsing the values in the curly braces.
Try this:
Try this:
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // Identify this question var qID = {QID}; var thisQuestion = $('#question'+qID); // Remove LS imposed column widths $('colgroup', thisQuestion).remove(); // Move the table cells $('table.subquestion-list thead tr', thisQuestion).each(function(i, thisRow) { $('td.header_separator', thisRow).after($('th.header_answer_text', thisRow)).remove(); }); $('tr.answers-list', thisQuestion).each(function(i, thisRow) { $('td.dual_scale_separator', thisRow).after($('th.answertext', thisRow)).remove(); }); // Insert some clean-up styles (could be placed in template.css) var newStyles = '<style type="text/css">\n'+ '#question'+qID+' th.header_answer_text, #question'+qID+' th.answertext {\n'+ 'width:50%;\n'+ 'text-align:center;\n'+ 'hyphens: none;\n'+ 'overflow-wrap: normal;\n'+ '}\n'+ '#question'+qID+' td.radio-item {\n'+ 'padding: 10px;\n'+ '}\n'+ '#question'+qID+' .radio label::before, #question'+qID+' .radio label::after {\n'+ 'margin-left: 0;\n'+ '}\n'+ '@media only screen and (max-width: 801px) {\n'+ '#question'+qID+' th.answertext {\n'+ 'clear: both;\n'+ 'text-align: left;\n'+ '}\n'+ '#question'+qID+' td.radio-item {\n'+ 'float: left;\n'+ 'width: auto !important;\n'+ '}\n'+ '}\n'+ '</style>' $('head').append(newStyles); }); </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.
- VAMOS_FHB
- Offline
- New Member
Less
More
- Posts: 7
- Thank you received: 0
6 years 3 weeks ago #167050
by VAMOS_FHB
Replied by VAMOS_FHB on topic Need help with dual Array with question in the middle...
Thank you for your help! With your code the EM is now working. But the answers are no longer in the middle of the dual array. In my example both arrays are now identical. So there there is no difference in the result compared to just using the "standard" dual array without any javascript code.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10115
- Thank you received: 3597
6 years 3 weeks ago #167059
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 Need help with dual Array with question in the middle...
Ah, Expression Manager again - no spaces after some opening curly braces. Use this code:
Here is your sample survey back:
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // Identify this question var qID = {QID}; var thisQuestion = $('#question'+qID); // Remove LS imposed column widths $('colgroup', thisQuestion).remove(); // Move the table cells $('table.subquestion-list thead tr', thisQuestion).each(function(i, thisRow) { $('td.header_separator', thisRow).after($('th.header_answer_text', thisRow)).remove(); }); $('tr.answers-list', thisQuestion).each(function(i, thisRow) { $('td.dual_scale_separator', thisRow).after($('th.answertext', thisRow)).remove(); }); // Insert the center header label var centerHeader = ' '; $('table.subquestion-list thead tr:eq(0) th.header_answer_text', thisQuestion).text(centerHeader); // Insert some clean-up styles (could be placed in template.css) var newStyles = '<style type="text/css">\n'+ '#question'+qID+' th.header_answer_text, #question'+qID+' th.answertext { \n'+ 'width:50%;\n'+ 'text-align:center;\n'+ 'hyphens: none;\n'+ 'overflow-wrap: normal;\n'+ '}\n'+ '#question'+qID+' td.radio-item { \n'+ 'padding: 10px;\n'+ '}\n'+ '#question'+qID+' .radio label::before, #question'+qID+' .radio label::after { \n'+ 'margin-left: 0;\n'+ '}\n'+ '@media only screen and (max-width: 801px) { \n'+ '#question'+qID+' th.answertext { \n'+ 'clear: both;\n'+ 'text-align: left;\n'+ '}\n'+ '#question'+qID+' td.radio-item { \n'+ 'float: left;\n'+ 'width: auto !important;\n'+ '}\n'+ '}\n'+ '</style>' $('head').append(newStyles); }); </script>
Here is your sample survey back:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The topic has been locked.