Welcome, Guest
Username: Password: Remember me

TOPIC: Filter on empty and zero (0)

Filter on empty and zero (0) 2 years 2 months ago #86124

  • TAdams
  • TAdams's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 24
  • Thank you received: 1
  • Karma: 0
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.
The administrator has disabled public write access.

Re: Filter on empty and zero (0) 2 years 2 months ago #86126

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
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
The administrator has disabled public write access.

Re: Filter on empty and zero (0) 2 years 2 months ago #86174

  • TAdams
  • TAdams's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 24
  • Thank you received: 1
  • Karma: 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>
The administrator has disabled public write access.

Re: Filter on empty and zero (0) 2 years 2 months ago #86175

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
TAdams, try asking Tony (tpartner) - he is the resident JavaScript guru
The administrator has disabled public write access.

Re: Filter on empty and zero (0) 2 years 1 month ago #86291

  • TAdams
  • TAdams's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 24
  • Thank you received: 1
  • Karma: 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.
Last Edit: 2 years 1 month ago by TAdams.
The administrator has disabled public write access.

Re: Filter on empty and zero (0) 2 years 1 month ago #86408

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4372
  • Thank you received: 830
  • Karma: 381
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Filter on empty and zero (0) 2 years 1 month ago #86488

  • TAdams
  • TAdams's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 24
  • Thank you received: 1
  • Karma: 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.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.219 seconds
Donation Image