Array filter with array with numbers

More
5 days 18 hours ago #230964 by depinstitut
Please help us help you and fill where relevant: 
Your LimeSurvey version: Version 5.3.25
Own server or LimeSurvey hosting:  LimeSurvey hosting
Survey theme/template: Extension of fruity.
==================
We are trying to do an Array -Numbers with Checkbox display, that has answer response filters from a previous question for the rows and that doesn't allow for more than 3 responses per row and also excludes other responses on the row if the respondent answers N/NC. 
For now in the equation of the subquestion we have established that you can't continue if you mark more than 3 responses but if you select all the options on the previous question that is the filter array - it stops working. 
The survey/questions can be seen here:  depinstitut.limequery.org/416864?lang=ca  Thank you for any help/guidance in advance, 
Rachel
Attachments:

Please Log in to join the conversation.

More
5 days 17 hours ago #230968 by tpartner
Regarding the exclusive column, see the second script here - forums.limesurvey.org/forum/search?query...artner&childforums=1

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
5 days 17 hours ago #230969 by Joffm
Hi,
1. You should use ".NAOK" in your question validation.
2. It is a question validation, not a subquestion validation.
3. I included the script Tony mentioned.
4. I can't reproduce that something stops working, even in your linked survey.

 

File Attachment:

File Name: limesurvey... (1).lss
File Size:62 KB


 
Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:

Please Log in to join the conversation.

More
5 days 17 hours ago #230971 by tpartner
Here is a script that will:
1) Render the last column as exclusive
2) Limit the non-exclusive items to a max of 3 per row.

This can be used in conjunction with Joffm's validation.

<script type="text/javascript" data-author="Tony Partner">
	$(document).on('ready pjax:scriptcomplete',function(){
 
		var thisQuestion = $('#question{QID}')
 
		// Add some classes to the checkbox cells
		$('td.checkbox-item', thisQuestion).addClass('normal-item');
		$('tr.subquestion-list', thisQuestion).each(function(i) {
			$('.normal-item:last', this).removeClass('normal-item').addClass('exclusive-item')
		});
 
		// A listener on the checkboxes
		$('input[type="checkbox"]', thisQuestion).on('change', function (event) {
			handleCheckboxes($(this));
		});
 
		function handleCheckboxes(thisInput) {
 
			var thisCell = $(thisInput).closest('td'); 
			var thisRow = $(thisCell).closest('tr');
 
			$('input[type="checkbox"]', thisRow).prop('disabled', false);
			$('td', thisRow).closest('td').removeClass('checked-item');
			$('input[type="checkbox"]:checked', thisRow).closest('td').addClass('checked-item');
 
			// Exclusive item
			if($('.exclusive-item input[type="checkbox"]:eq(0)', thisRow).is(':checked')) {
				$('.normal-item input[type="hidden"]', thisRow).val('');
				$('.normal-item input[type="checkbox"]', thisRow).prop('checked', false).prop('disabled', true);
			}
			else {
				$('.exclusive-item input[type="hidden"]', thisRow).val('');
				$('.exclusive-item input[type="checkbox"]', thisRow).prop('checked', false);
			}
 
			// Max 3 answers per row
			if($('input[type="checkbox"]:checked', thisRow).length == 3) {
				$('td:not(.exclusive-item):not(.checked-item)', thisRow).find('input[type="checkbox"]').prop('disabled', true);
			}
 
			// Check conditions (relevance)
			$('td.checkbox-item', thisRow).each(function(i) {
				var thisValue = '';
				if($('input[type="checkbox"]', this).is(':checked')) {
					thisValue = 1;
				}
				var thisSGQA = $('input[type="checkbox"]', this).attr('id').replace(/cbox_/, '');
 
				$('input[type="hidden"]', this).attr('value', thisValue);
				fixnum_checkconditions(thisValue, thisSGQA, 'hidden');
			});
		}
	});
</script>

Sample survey attached: 

File Attachment:

File Name: limesurvey...4(1).lss
File Size:62 KB

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

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now