Hide array cells with condition

Más
1 año 5 meses antes - 1 año 5 meses antes #167572 por 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.
Última Edición: 1 año 5 meses antes por AlessandraAndreotti.

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

LimeSurvey Partners
Más
1 año 5 meses antes #167576 por Joffm
Respuesta de Joffm sobre el tema 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
Adjuntos:

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

Más
1 año 5 meses antes #167601 por 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
Adjuntos:

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

Más
1 año 5 meses antes #167624 por tpartner
Respuesta de tpartner sobre el tema 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

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

Más
1 año 5 meses antes - 1 año 5 meses antes #167625 por 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
Última Edición: 1 año 5 meses antes por AlessandraAndreotti.

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

Más
1 año 5 meses antes #167637 por tpartner
Respuesta de tpartner sobre el tema 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:

Archivo Adjunto:

Nombre del Archivo: limesurvey...1921.lss
Tamaño del Archivo:24 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
Adjuntos:
El siguiente usuario dijo gracias: AlessandraAndreotti

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

Más
1 año 5 meses antes #167642 por AlessandraAndreotti
Thank you very much!
It works!

Best,
Alessandra

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

¡Comenzar ahora!

Simplemente cree una cuenta y comience a usar LimeSurvey hoy mismo.

Registrarse ahora
¡Únase a nuestro boletín informativo!

Iniciar sesión