Last Option In Array (Numbers) (Checkboxes) column Excludes All Others

More
1 year 6 months ago #208762 by surveySn
Hello everyone,
Last Option In Array (Numbers) (Checkboxes) column Excludes All Others
manual.limesurvey.org/Workarounds:_Manip..._Excludes_All_Others
How do it?

I searched the forum and there was no answer to the column.
The topic has been locked.
More
1 year 6 months ago - 1 year 6 months ago #208764 by tpartner
Do not double-post.

I searched the forum and there was no answer to the column.

- forums.limesurvey.org/forum/can-i-do-thi...-all-others&start=15

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 1 year 6 months ago by tpartner.
The topic has been locked.
More
1 year 6 months ago #208766 by surveySn
forums.limesurvey.org/forum/can-i-do-thi...-all-others&start=15
This is row exclusive,

I want to be column exclusive,

could you help me,
Version 3.22.11 + 200330
The topic has been locked.
More
1 year 6 months ago #208767 by surveySn
The topic has been locked.
More
1 year 6 months ago #208769 by tpartner

surveySn wrote: This is row exclusive,

I want to be column exclusive

Huh?


Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The topic has been locked.
More
1 year 6 months ago #208771 by surveySn
Attachments:
The topic has been locked.
More
1 year 6 months ago #208789 by tpartner
Oh, an exclusive row...

Can you attach a small sample survey (.lss file) containing only that question?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
1 year 6 months ago #208796 by surveySn
SQ007_A and SQ007_B and SQ007_C and SQ007_D and SQ007_E and SQ007_F and SQ007_G It's exclusive

File Attachment:

File Name: limesurvey...3221.lss
File Size:22 KB
Attachments:
The topic has been locked.
More
1 year 6 months ago - 1 year 6 months ago #208815 by tpartner
So, to be clear...

Every row is exclusive (only one answer per column) or the last row is exclusive (last row excludes all other answers in the same column)?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 1 year 6 months ago by tpartner.
The topic has been locked.
More
1 year 6 months ago #208823 by surveySn
the last row is exclusive (last row excludes all other answers in the same column)
My English is poor and I don't express myself clearly,:kiss:
The topic has been locked.
More
1 year 6 months ago #208844 by tpartner
Add this script to the source of the question:

<script type="text/javascript" charset="utf-8">	
	$(document).on('ready pjax:scriptcomplete',function(){
 
		// Identify this question
		var qID = '{QID}';
		var thisQuestion = $('#question'+qID);
 
		// Assign column-specific attributes and classnames
		$('tr.subquestion-list', thisQuestion).each(function(i) {
			$('> *', this).each(function(i) {
				$(this).attr('data-column', i);
			});
		});
		$('tr.subquestion-list:last td.answer-item', thisQuestion).addClass('exclusive-item');
 
		// A function to un-check boxes
		function resetCheckbox(thisItem) {
			$(':hidden', thisItem).val('');
			$(':checkbox', thisItem).prop('checked', false).trigger('change');
		}
 
		// Listener on the checkboxes
		$(':checkbox', thisQuestion).on('change', function(e) {
			if($(this).is(':checked')) {
				var thisItem = $(this).closest('.answer-item');
				var thisColumn = $(thisItem).attr('data-column');
				var items = $('td.answer-item[data-column="'+thisColumn+'"].exclusive-item', thisQuestion);
				if($(thisItem).hasClass('exclusive-item')) {
					items = $('td.answer-item[data-column="'+thisColumn+'"]:not(.exclusive-item)', thisQuestion);
				}
				$.each(items, function(i, el) {
					resetCheckbox(el);
				});
			}
		});
    });
</script>

Here is a sample survey:

File Attachment:

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

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The topic has been locked.
More
1 year 6 months ago #208856 by surveySn
Great Tony,

thank you,



I have another question,

I play random sub problems,

fixed the last item,
<script type="text/javascript" charset="utf-8">	
	$(document).ready(function() {
 
		// The subquestion code to place in the last position
		var fixedCode = 'A20';
 
		// Identify this question
		var q1ID = {QID};
		var thisQuestion = $('#question'+q1ID);
 
		// Move the "fixed" row to the end
		$('table.subquestion-list tbody:last', thisQuestion).append($('tr[id$="X'+q1ID+fixedCode+'"]'));
 
		// Fix up the array row background colours
		$('tr.answers-list', thisQuestion).each(function(i){
			$(this).removeClass('array1 array2').addClass('array'+(2-(i%2)));
		});
 
    });
</script>

Use your script,
<script type="text/javascript" charset="utf-8">	
	$(document).on('ready pjax:scriptcomplete',function(){
 
		// Identify this question
		var qID = '{QID}';
		var thisQuestion = $('#question'+qID);
 
		// Assign column-specific attributes and classnames
		$('tr.subquestion-list', thisQuestion).each(function(i) {
			$('> *', this).each(function(i) {
				$(this).attr('data-column', i);
			});
		});
		$('tr.subquestion-list:last td.answer-item', thisQuestion).addClass('exclusive-item');
 
		// A function to un-check boxes
		function resetCheckbox(thisItem) {
			$(':hidden', thisItem).val('');
			$(':checkbox', thisItem).prop('checked', false).trigger('change');
		}
 
		// Listener on the checkboxes
		$(':checkbox', thisQuestion).on('change', function(e) {
			if($(this).is(':checked')) {
				var thisItem = $(this).closest('.answer-item');
				var thisColumn = $(thisItem).attr('data-column');
				var items = $('td.answer-item[data-column="'+thisColumn+'"].exclusive-item', thisQuestion);
				if($(thisItem).hasClass('exclusive-item')) {
					items = $('td.answer-item[data-column="'+thisColumn+'"]:not(.exclusive-item)', thisQuestion);
				}
				$.each(items, function(i, el) {
					resetCheckbox(el);
				});
			}
		});
    });
</script>

Not the last row excludes



File Attachment:

File Name: limesurvey...9278.lss
File Size:30 KB
Attachments:
The topic has been locked.
More
1 year 6 months ago - 1 year 6 months ago #208865 by tpartner
Apply the exclusive script before the fixed-row script.

<script type="text/javascript" charset="utf-8">	
	$(document).on('ready pjax:scriptcomplete',function(){
 
		// Identify this question
		var qID = '{QID}';
		var thisQuestion = $('#question'+qID);
 
		// Assign column-specific attributes and classnames
		$('tr.subquestion-list', thisQuestion).each(function(i) {
			$('> *', this).each(function(i) {
				$(this).attr('data-column', i);
			});
		});
		$('tr.subquestion-list:last td.answer-item', thisQuestion).addClass('exclusive-item');
 
		// A function to un-check boxes
		function resetCheckbox(thisItem) {
			$(':hidden', thisItem).val('');
			$(':checkbox', thisItem).prop('checked', false).trigger('change');
		}
 
		// Listener on the checkboxes
		$(':checkbox', thisQuestion).on('change', function(e) {
			if($(this).is(':checked')) {
				var thisItem = $(this).closest('.answer-item');
				var thisColumn = $(thisItem).attr('data-column');
				var items = $('td.answer-item[data-column="'+thisColumn+'"].exclusive-item', thisQuestion);
				if($(thisItem).hasClass('exclusive-item')) {
					items = $('td.answer-item[data-column="'+thisColumn+'"]:not(.exclusive-item)', thisQuestion);
				}
				$.each(items, function(i, el) {
					resetCheckbox(el);
				});
			}
		});
 
		// The subquestion code to place in the last position
		var fixedCode = 'A20';
 
		// Move the "fixed" row to the end
		$('table.subquestion-list tbody:last', thisQuestion).append($('tr[id$="X'+qID+fixedCode+'"]'));
 
		// Fix up the array row background colours
		$('tr.answers-list', thisQuestion).each(function(i){
			$(this).removeClass('array1 array2').addClass('array'+(2-(i%2)));
		});
    });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 1 year 6 months ago by tpartner.
The topic has been locked.
More
1 year 6 months ago #208868 by surveySn
Hi Tony


If random order is used

Can't fixed the last row,

File Attachment:

File Name: limesurvey... (1).lss
File Size:30 KB
Attachments:
The topic has been locked.
More
1 year 6 months ago #208891 by tpartner
<script type="text/javascript" charset="utf-8">	
	$(document).on('ready pjax:scriptcomplete',function(){
 
		// Identify this question
		var qID = '{QID}';
		var thisQuestion = $('#question'+qID);
 
		// Assign column-specific attributes and classnames
		$('tr.subquestion-list', thisQuestion).each(function(i) {
			$('> *', this).each(function(i) {
				$(this).attr('data-column', i);
			});
		});
		$('tr.subquestion-list:last td.answer-item', thisQuestion).addClass('exclusive-item');
 
		// A function to un-check boxes
		function resetCheckbox(thisItem) {
			$(':hidden', thisItem).val('');
			$(':checkbox', thisItem).prop('checked', false).trigger('change');
		}
 
		// Listener on the checkboxes
		$(':checkbox', thisQuestion).on('change', function(e) {
			if($(this).is(':checked')) {
				var thisItem = $(this).closest('.answer-item');
				var thisColumn = $(thisItem).attr('data-column');
				var items = $('td.answer-item[data-column="'+thisColumn+'"].exclusive-item', thisQuestion);
				if($(thisItem).hasClass('exclusive-item')) {
					items = $('td.answer-item[data-column="'+thisColumn+'"]:not(.exclusive-item)', thisQuestion);
				}
				$.each(items, function(i, el) {
					resetCheckbox(el);
				});
			}
		});
 
		// The subquestion code to place in the last position
		var fixedCode = 'A20';
 
		// Move the "fixed" row to the end
		$('table.subquestion-list tbody:last', thisQuestion).append($('tr[id$="X'+qID+fixedCode+'"]'));
 
		// Fix up the array row background colours
		$('tr.answers-list', thisQuestion).each(function(i){
			$(this).removeClass('array1 array2').addClass('array'+(2-(i%2)));
		});
    });
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...9278.lss
File Size:31 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The topic has been locked.

Start now!

Just create your account and start using Limesurvey today.

Register now