- Posts: 28
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Hide array cells with condition
- AlessandraAndreotti
- Topic Author
- Offline
- Junior Member
Less
More
6 years 1 week ago - 6 years 1 week ago #167572
by AlessandraAndreotti
Hide array cells with condition was created by AlessandraAndreotti
Hi!
I need to hide some cells of the array B based on the answer in the array A.
For example, if question Q001 of the array A is not answered, so the question Q001 of the array B must be hide.
Thanks in advance.
I need to hide some cells of the array B based on the answer in the array A.
For example, if question Q001 of the array A is not answered, so the question Q001 of the array B must be hide.
Thanks in advance.
Last edit: 6 years 1 week ago by AlessandraAndreotti.
The topic has been locked.
- Joffm
- Away
- LimeSurvey Community Team
Less
More
- Posts: 12941
- Thank you received: 3979
6 years 1 week ago #167576
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Hide array cells with condition
Hi, Alessandra,
you are not very clear.
You say you would like
But here it seems you want to hide some subquestions
Well, assuming you use a "normal" arrayA with subquestions "SQ001", "SQ002", ...
This array seems to be "not mandatory", because you say
Now you already know the relevance equation of the subquestions of arrayB
!is_empty(arrayA_SQ001)
!is_empty(arrayA_SQ002)
...
meaning: the subquestions of arrayB are only displayed if this subquestion in arrayA is NOT empty.
Joffm
P.S. If the "not answered" means that the respondent clicked "not answered" it's a bit different:
arrayA_SQ001!=[code_no_answer]
you are not very clear.
You say you would like
to hide some cells of the array B
But here it seems you want to hide some subquestions
the question Q001 of the array B must be hide
Well, assuming you use a "normal" arrayA with subquestions "SQ001", "SQ002", ...
This array seems to be "not mandatory", because you say
.if question Q001 of the array A is not answered
Now you already know the relevance equation of the subquestions of arrayB
!is_empty(arrayA_SQ001)
!is_empty(arrayA_SQ002)
...
meaning: the subquestions of arrayB are only displayed if this subquestion in arrayA is NOT empty.
Joffm
P.S. If the "not answered" means that the respondent clicked "not answered" it's a bit different:
arrayA_SQ001!=[code_no_answer]
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
The topic has been locked.
- AlessandraAndreotti
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 28
- Thank you received: 0
6 years 6 days ago #167601
by AlessandraAndreotti
Replied by AlessandraAndreotti on topic Hide array cells with condition
Hi Joffm,
thanks for your prompt reply.
I've explained myself badly.
In attachment you can find my LimeSurvey example.
I need that subquestion D2_D2Y1xD2X1 on page2 to be hidden if subquestion D1_D1Y1xD1X1 is not answered.
In the attached images, I've circled in red the subquestion that must be hidden on page 2.
Thanks in advance.
Alessandra
thanks for your prompt reply.
I've explained myself badly.
In attachment you can find my LimeSurvey example.
I need that subquestion D2_D2Y1xD2X1 on page2 to be hidden if subquestion D1_D1Y1xD1X1 is not answered.
In the attached images, I've circled in red the subquestion that must be hidden on page 2.
Thanks in advance.
Alessandra
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
6 years 6 days ago #167624
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 array cells with condition
As far as I know, the only way to do that would be with JavaScript.
Do you need it for all cells in the second array?
Do you need it for all cells in the second array?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- AlessandraAndreotti
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 28
- Thank you received: 0
6 years 6 days ago - 6 years 6 days ago #167625
by AlessandraAndreotti
Replied by AlessandraAndreotti on topic Hide array cells with condition
Hi tpartner,
thank you for the reply.
Yes, I need it for all cells in the second array.
I've found the following Java script in the web, but I don't be able to adapt it for my necessity.
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('input[name="69965X2X10SQ001_SQ001"]').attr('disabled', 'disabled');
});
</script>
I don't know if it is the correct java script...
Thanks for your help in advance.
Alessandra
thank you for the reply.
Yes, I need it for all cells in the second array.
I've found the following Java script in the web, but I don't be able to adapt it for my necessity.
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('input[name="69965X2X10SQ001_SQ001"]').attr('disabled', 'disabled');
});
</script>
I don't know if it is the correct java script...
Thanks for your help in advance.
Alessandra
Last edit: 6 years 6 days ago by AlessandraAndreotti.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
6 years 6 days ago #167637
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 array cells with condition
1) Place something like this in the source of the second array. It will render a hidden array of all answered Q1 sub-question codes that we can access with JavaScript.
2) Add this script to the source of Q2. It will loop through that hidden array and disable Q2 sub-questions if the corresponding Q1 sub-question was not answered.
Here is your sample survey back with those modifications:
Code:
<div class="hidden equation"> {implode(',', if(D1_D1Y1_D1X1 == '1', 'D1Y1_D1X1', ''), if(D1_D1Y1_D1X2 == '1', 'D1Y1_D1X2', ''), if(D1_D1Y1_D1X3 == '1', 'D1Y1_D1X3', ''), if(D1_D1Y2_D1X1 == '1', 'D1Y2_D1X1', ''), if(D1_D1Y2_D1X2 == '1', 'D1Y2_D1X2', ''), if(D1_D1Y2_D1X3 == '1', 'D1Y2_D1X3', ''), if(D1_D1Y3_D1X1 == '1', 'D1Y3_D1X1', ''), if(D1_D1Y3_D1X2 == '1', 'D1Y3_D1X2', ''), if(D1_D1Y3_D1X3 == '1', 'D1Y3_D1X3', ''), if(D1_D1Y4_D1X1 == '1', 'D1Y4_D1X1', ''), if(D1_D1Y4_D1X2 == '1', 'D1Y4_D1X2', ''), if(D1_D1Y4_D1X3 == '1', 'D1Y4_D1X3', ''))} </div>
2) Add this script to the source of Q2. It will loop through that hidden array and disable Q2 sub-questions if the corresponding Q1 sub-question was not answered.
Code:
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ var q1Code = 'D1'; var q2Code = 'D2'; var answeredQ1 = $.trim($('#question{QID} .hidden.equation:eq(0)').text()).split(','); // Loop through answers from Q1 and add classes to the corresponding Q2 inputs $.each(answeredQ1, function(i, val) { var re = new RegExp(q1Code, 'g'); var q2CellCode = val.replace(re, q2Code); if(val != '') { $('#question{QID} input[type="text"][id$="'+q2CellCode+'"]').addClass('relevant'); } }); // Disable irrelevant items $('#question{QID} input[type="text"]:not(.relevant)').prop('disabled', true).val(''); }); </script>
Here is your sample survey back with those modifications:
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: AlessandraAndreotti
The topic has been locked.
- AlessandraAndreotti
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 28
- Thank you received: 0
6 years 6 days ago #167642
by AlessandraAndreotti
Replied by AlessandraAndreotti on topic Hide array cells with condition
Thank you very much!
It works!
Best,
Alessandra
It works!
Best,
Alessandra
The topic has been locked.