Filter on empty and zero (0)

Más
6 años 9 meses antes #86124 por TAdams
I have a multiple numerical input question that I would like to use throughout my survey as a filter. Currently when I set the array filter in subsequent questions it only filters the array rows if a multiple numerical input text field is empty. I need it to filter if empty or if zero (0).
If I set the question to not mandatory and just filter if empty users may still choose to enter zero (0) and in that situation I would still like the rows to be hidden in subsequent filtered questions.
I have javascript that will work similar to the filter but if I can get the filters to work that would be preferable.

Thank you in advance.

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

LimeSurvey Partners
Más
6 años 9 meses antes #86126 por TMSWhite
Respuesta de TMSWhite sobre el tema Filter on empty and zero (0)
As you have probably seen, when you use array filter, the auto-generated relevance for each sub-question is something like this:
!is_empty(q1_sq3.NAOK)

You want the auto-generated code to be:
(!is_empty(q1_sq3.NAOK) and q1_sq3.NAOK != 0)

There are two ways to do that, both of which would require enhancements:
(1) Provide a new advanced question attribute called, perhaps, array_filter_alternate_missing_values, which could be a semi-colon delimited set of values that would be treated by the array_filter as a missing value. The reason for not just using 0 is that authors might want to give users the option to enter values like 888 or 999 to indicate that the choices are not applicable, or that they refuse to answer.
(2) Implement a GUI for sub-question relevance. That way each sub-question could have an additional relevance clause added to it which would be anded to anything auto-generated by the array-filter routines. This approach is more complicated, but would support a common request for that functionality.

/Tom

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

Más
6 años 9 meses antes #86174 por TAdams
Respuesta de TAdams sobre el tema Filter on empty and zero (0)
Thanks Mr. White, I've decided to go with my original Javascript code to hide the array rows since it worked so well in the past. However I now have a new problem with INSERTANS and 1.92. Below is my code, can you help me understand how to collect and apply values from previous questions?

<script src="jquery.js"></script><script>
$(document).ready(function() {
var EH=('INSERTANS:777X1X1'));
var ES=('INSERTANS:777X1X2'));
var ES2=('INSERTANS:777X1X3');
var OE=('INSERTANS:777X1X4');
if( isNaN( EH ) ) EH = 0;
if( isNaN( ES ) ) ES = 0;
if( isNaN( ES2 ) ) ES2 = 0;
if( isNaN( OE ) ) OE = 0;

if (EH<=0)
document.getElementById("javatbd777X1X61").style.display='none';
if (ES<=0)
document.getElementById("javatbd777X1X62").style.display='none';
if (ES2<=0)
document.getElementById("javatbd777X1X63").style.display='none';
if (OE<=0)
document.getElementById("javatbd777X1X64").style.display='none';
});
</script>

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

Más
6 años 9 meses antes #86175 por TMSWhite
Respuesta de TMSWhite sobre el tema Filter on empty and zero (0)
TAdams, try asking Tony (tpartner) - he is the resident JavaScript guru

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

Más
6 años 9 meses antes - 6 años 9 meses antes #86291 por TAdams
Respuesta de TAdams sobre el tema Filter on empty and zero (0)
Thanks TMS. I have emailed tpartner but I have not yet heard back. However, I have changed my coding to:
$(document).ready(function() {
var EH = document.getElementById(LEMval('777X1X1'));
var ES = document.getElementById(LEMval('777X1X2'));
var ES2 = document.getElementById(LEMval('777X1X3'));
var OE = document.getElementById(LEMval('777X1X4'));
if( isNaN( EH ) ) EH = 0;
if( isNaN( ES ) ) ES = 0;
if( isNaN( ES2 ) ) ES2 = 0;
if( isNaN( OE ) ) OE = 0;
if (EH<=0)
document.getElementById("javatbd777X1X21").style.display='none';
if (ES<=0)
document.getElementById("javatbd777X1X22").style.display='none';
if (ES2<=0)
document.getElementById("javatbd777X1X23").style.display='none';
if (OE<=0)
document.getElementById("javatbd777X1X24").style.display='none';
});
And now I get an error regarding the em_javascript.js:
if ((suffix.match(/^code|NAOK|shown|valueNAOK|value$/)) && attr.qid!='') {
if (!LEMval(varName + '.relevanceStatus')) {
return '';
}
}
Of course this is not my code so I'm afraid I've hit some kind of glitch. Any suggestions?

Thank you in advance.
Última Edición: 6 años 9 meses antes por TAdams.

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

Más
6 años 9 meses antes #86408 por tpartner
Respuesta de tpartner sobre el tema Filter on empty and zero (0)
I can't speak to the Expression Manager errors but here is the previous code snippet with a few syntax errors fixed. Note that INSERTANS only works for questions on previous pages.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
		var EH= 'INSERTANS:777X1X1';
		var ES= 'INSERTANS:777X1X2';
		var ES2= 'INSERTANS:777X1X3';
		var OE= 'INSERTANS:777X1X4';
 
		if(isNaN(EH)) { 
			EH = 0;
		}
		if(isNaN(ES)) { 
			ES = 0;
		}
		if(isNaN(ES2)) { 
			ES2 = 0;
		}
		if(isNaN(OE)) { 
			OE = 0;
		}
 
		if (EH <= 0) { 
			$("#javatbd777X1X61").hide();
		}
		if (ES <= 0) { 
			$("#javatbd777X1X62").hide();
		}
		if (ES2 <= 0) { 
			$("#javatbd777X1X63").hide();
		}
		if (OE <=0 ) { 
			$("#javatbd777X1X64").hide();
		}
	});
 
</script>

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
6 años 9 meses antes #86488 por TAdams
Respuesta de TAdams sobre el tema Filter on empty and zero (0)
:cheer: Thanks to both of you for all your help. After a great deal of trial and error the problem all along was my error trapping ( if( isNaN( EH ) ) EH = 0; )and not INSERTANS. Once I made tpartner's suggested changes ( if(isNaN(EH)) { EH = 0;}) everything worked perfectly. Thanks also to tpartner for the suggested shortcuts. I tend to take the long way.

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