- Posts: 18
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Hide column in array question
- giovbod
- Topic Author
- Offline
- New Member
Less
More
3 years 1 month ago #212506
by giovbod
Hide column in array question was created by giovbod
Hi Everyone,
I have an array question (let's say 5 rows and 4 columns) and I want to hide one specific column according to the answer to the previous question.
Let's say:
Q1: (multiple coiches) Which column do you want to hide?
Possible answers: A1 = column A, A2 = column B, A3 = column C, A4=column D
I planned to put something like {if(Q1_A1=="Y"} as relevance equation, but I noticed there is no relevance equation for columns in arrays.
What should I do? I saw there is a plugin to hide a column if the label is empty, but it seems in my installation (limesurvey in docker) I cannot access via ssh and therefore I cannot install plugin (unless there is a way from the web interface ...).
Anyone can help me?
Than k you in advance
I have an array question (let's say 5 rows and 4 columns) and I want to hide one specific column according to the answer to the previous question.
Let's say:
Q1: (multiple coiches) Which column do you want to hide?
Possible answers: A1 = column A, A2 = column B, A3 = column C, A4=column D
I planned to put something like {if(Q1_A1=="Y"} as relevance equation, but I noticed there is no relevance equation for columns in arrays.
What should I do? I saw there is a plugin to hide a column if the label is empty, but it seems in my installation (limesurvey in docker) I cannot access via ssh and therefore I cannot install plugin (unless there is a way from the web interface ...).
Anyone can help me?
Than k you in advance
Please Log in to join the conversation.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10634
- Thank you received: 3698
3 years 1 month ago #212537
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 Hide column in array question
Assuming that the filter question is on a previous page...
1) In the array answers, insert hidden <span> elements to hold the values of the filter checkboxes:
2) Place this code in the source of the array:
Sample survey attached:
1) In the array answers, insert hidden <span> elements to hold the values of the filter checkboxes:
2) Place this code in the source of the array:
Code:
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ // Identify this question var qID = {QID}; var thisQuestion = $('#question'+qID); var thisTable = $('table.subquestion-list:eq(0)', thisQuestion) $($('.answer-text .filter', thisTable).get().reverse()).each(function(i) { var thisIndex = $(this).closest('th').index(); var filter = $.trim($(this).text()); if($('span[id^="LEMtailor"]', this).length > 0) { filter = $.trim($('span[id^="LEMtailor"]', this).text()) } if(filter == 'Y') { hideColumn(thisIndex) } }); function hideColumn(index) { $('col:nth-child('+(index+1)+'), thead .answer-text:nth-child('+(index+1)+'), tr.answers-list .answer-item:nth-child('+(index+1)+')', thisTable).hide(); $('tr.answers-list .answer-item:nth-child('+(index+1)+') :radio:checked', thisTable).each(function(i) { $(this).prop('checked', false); checkconditions('', $(this).attr('name'), $(this).attr('type')); }); } }); </script>
Sample survey attached:
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: giovbod, tenroc
Please Log in to join the conversation.
- tenroc
- Offline
- New Member
Less
More
- Posts: 2
- Thank you received: 0
2 years 6 months ago #219573
by tenroc
Replied by tenroc on topic Hide column in array question
Thanks a lot for the code!
It works great, but only for normal arrays. Could the same be achieved for Numbers arrays?
It works great, but only for normal arrays. Could the same be achieved for Numbers arrays?
Please Log in to join the conversation.
- rolasj
- Offline
- New Member
Less
More
- Posts: 8
- Thank you received: 0
2 years 6 months ago - 2 years 6 months ago #219885
by rolasj
Replied by rolasj on topic Hide column in array question
But this work only in array questions (with radio buttons) (example
limesurvey...9381.lss
)
if i use array(numbers) it doesn't work for me
can anyone help?
if i use array(numbers) it doesn't work for me
can anyone help?
Last edit: 2 years 6 months ago by rolasj.
Please Log in to join the conversation.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12789
- Thank you received: 3940
2 years 6 months ago #219886
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Hide column in array question
Please have a look at the plugin "hideEmptyColumn".
[url] gitlab.com/SondagesPro/QuestionSettingsType/hideEmptyColumn [/url]
Demo survey is included.
Joffm
[url] gitlab.com/SondagesPro/QuestionSettingsType/hideEmptyColumn [/url]
Demo survey is included.
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: DenisChenu
Please Log in to join the conversation.
- rolasj
- Offline
- New Member
Less
More
- Posts: 8
- Thank you received: 0
2 years 6 months ago #219988
by rolasj
Replied by rolasj on topic Hide column in array question
Thanks,
works great
i use limesurvey 3.17.1
... is it possible and how this can be done with just one survey or one question?
works great
i use limesurvey 3.17.1
... is it possible and how this can be done with just one survey or one question?
Please Log in to join the conversation.
- tenroc
- Offline
- New Member
Less
More
- Posts: 2
- Thank you received: 0
2 years 6 months ago - 2 years 6 months ago #219990
by tenroc
Replied by tenroc on topic Hide column in array question
For anyone that isn't allowed to install plugins on their limesurvey instance, this works for me on numbered array:
This is just a slight modification of the code previously posted here for normal arrays. So the procedure is the same.
My javascript skills are pretty awful, be sure to test thoroughly before deploying this.
Code:
<script type="text/javascript"> $(document).on('ready pjax:scriptcomplete',function(){ // Identify this question var qID = {QID}; var thisQuestion = $('#question'+qID); var thisTable = $('table.subquestion-list:eq(0)', thisQuestion) $($('.ls-heading .filter', thisTable).get().reverse()).each(function(i) { var lineRead = $($('.ls-heading .filter', thisTable).get().reverse()); var thisIndex = $(this).closest('th').index(); var filter = $.trim($(this).text()); if($('span[id^="LEMtailor"]', this).length > 0) { filter = $.trim($('span[id^="LEMtailor"]', this).text()) } if(filter == 'Y') { hideColumn(thisIndex) } }); function hideColumn(index) { $('td.answer-item:nth-child('+(index+1)+')', thisTable).hide(); $('th.answertext:nth-child('+(index+1)+')', thisTable).hide(); $('tr.ls-heading th:nth-child('+(index+1)+')', thisTable).hide(); $('col:nth-child('+(index+1)+')', thisTable).hide(); } }); </script>
This is just a slight modification of the code previously posted here for normal arrays. So the procedure is the same.
My javascript skills are pretty awful, be sure to test thoroughly before deploying this.
Last edit: 2 years 6 months ago by tpartner. Reason: Remove author name from script
Please Log in to join the conversation.
- ecoplan
- Offline
- New Member
Less
More
- Posts: 14
- Thank you received: 0
1 year 8 months ago - 1 year 8 months ago #230612
by ecoplan
Replied by ecoplan on topic Hide column in array question
The scripts for array questions from TPartner as well as the adapted one for array (numbers) from tenroc worked fine for version 5.3.26. As of yesterday with the update to 5.3.27 they are not working anymore. (With 3.25.9 all good too)
The same goes for Joffm's method in his array workaround tutorial (it's super helpful btw:https://forums.limesurvey.org/forum/german-forum/125239-joffms-tutorial-1-matrizen-stand-27-10-2021)
His method (chapter 14) was working fine, aso of yesterday with V 5.3.27 it's not.
Any ideas?
The same goes for Joffm's method in his array workaround tutorial (it's super helpful btw:https://forums.limesurvey.org/forum/german-forum/125239-joffms-tutorial-1-matrizen-stand-27-10-2021)
His method (chapter 14) was working fine, aso of yesterday with V 5.3.27 it's not.
Any ideas?
Last edit: 1 year 8 months ago by ecoplan.
Please Log in to join the conversation.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10634
- Thank you received: 3698
1 year 8 months ago #230621
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 Hide column in array question
The problem is that for some reason the HTML structure of the array table was changed.
- bugs.limesurvey.org/view.php?id=18276
- bugs.limesurvey.org/view.php?id=18276
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: ecoplan
Please Log in to join the conversation.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10634
- Thank you received: 3698
1 year 8 months ago #230625
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 Hide column in array question
In the meantime while I lobby for reverting the "fix", this will work for arrays.
Sample survey attached:
Code:
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ // Identify this question var qID = {QID}; var thisQuestion = $('#question'+qID); var thisTable = $('table.subquestion-list:eq(0)', thisQuestion) $($('.answer-text .filter', thisTable).get().reverse()).each(function(i) { var thisIndex = $(this).closest('.answer-text').index(); var filter = $.trim($(this).text()); if($('span[id^="LEMtailor"]', this).length > 0) { filter = $.trim($('span[id^="LEMtailor"]', this).text()) } if(filter == 'Y') { hideColumn(thisIndex) } }); function hideColumn(index) { $('col:nth-child('+(index+1)+'), .ls-heading .answer-text:nth-child('+(index+1)+'), tr.answers-list .answer-item:nth-child('+(index+1)+')', thisTable).hide(); $('tr.answers-list .answer-item:nth-child('+(index+1)+') :radio:checked', thisTable).each(function(i) { $(this).prop('checked', false); checkconditions('', $(this).attr('name'), $(this).attr('type')); }); } }); </script>
Sample survey attached:
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: ecoplan
Please Log in to join the conversation.
- ecoplan
- Offline
- New Member
Less
More
- Posts: 14
- Thank you received: 0
1 year 8 months ago #230626
by ecoplan
Replied by ecoplan on topic Hide column in array question
Again big thank you tpartner for your efforts.
I should have noted the change in the table header elements (as of update to 5.3.27).
The adapted script works fine!
Let's see if I have to change back soon if the "fix" is reverted -> This is a reminder for everyone that the script in #230625 might be irrelevant again soon.
I should have noted the change in the table header elements (as of update to 5.3.27).
The adapted script works fine!
Let's see if I have to change back soon if the "fix" is reverted -> This is a reminder for everyone that the script in #230625 might be irrelevant again soon.
Please Log in to join the conversation.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10634
- Thank you received: 3698
1 year 8 months ago #230637
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 Hide column in array question
This will work if the "fix" is reverted.
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: ecoplan
Please Log in to join the conversation.