Hide array cells with condition

Plus d'informations
il y a 1 an 3 mois - il y a 1 an 3 mois #167572 par 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.
Dernière édition: il y a 1 an 3 mois par AlessandraAndreotti.

Connexion ou Créer un compte pour participer à la conversation.

LimeSurvey Partners
Plus d'informations
il y a 1 an 3 mois #167576 par Joffm
Réponse de Joffm sur le sujet Hide array cells with condition
Hi, Alessandra,

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
Pièces jointes :

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 1 an 3 mois #167601 par AlessandraAndreotti
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
Pièces jointes :

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 1 an 3 mois #167624 par tpartner
Réponse de tpartner sur le sujet 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?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 1 an 3 mois - il y a 1 an 3 mois #167625 par AlessandraAndreotti
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
Dernière édition: il y a 1 an 3 mois par AlessandraAndreotti.

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 1 an 3 mois #167637 par tpartner
Réponse de tpartner sur le sujet 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.

<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.

<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:

Fichier attaché :

Nom du fichier : limesurvey...1921.lss
Taille du ficher :24 ko

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
Pièces jointes :
Les utilisateur(s) suivant ont remercié: AlessandraAndreotti

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 1 an 3 mois #167642 par AlessandraAndreotti
Thank you very much!
It works!

Best,
Alessandra

Connexion ou Créer un compte pour participer à la conversation.

Commencez dès maintenant !

Créez simplement un compte et commencez à utiliser LimeSurvey dès aujourd'hui.

Inscrivez-vous maintenant

Inscrivez-vous à notre Newsletter!