Check out the LimeSurvey source code on GitHub!

Create unique options in array question

More
5 years 10 months ago #57449 by paulfiner
I have an array type question with some attributes down the side and three columns labelled Most important, 2nd most important and 3rd most important.

Is there a way to stop more than one attribute being selected as, say, Most important?

Cheers

Paul

Please Log in to join the conversation.

More
5 years 10 months ago #57450 by Mazi
You can test the Array Columns question type or switch to a ranking question type.
All other solution require some Javascript coding.


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
5 years 10 months ago #57453 by paulfiner
I've tried the Array Column question and the problem is the other way around i.e. an attribute can be selected as Most Important and 2nd Most important.
I'm happy to do it with some Javascript if someone can show me how.

I don't want to use the built in ranking question.

Cheers

Paul

Please Log in to join the conversation.

More
5 years 10 months ago #57464 by tpartner
Paul, are these radios or checkboxes? Do you want all columns to only allow one checked item or only one column? Can you attach a sample question (preferably in English)?

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 years 10 months ago #57465 by paulfiner
Hi Tony,

These are radiobuttons and should only allow 1 answer per column and not the same answer across columns.

Rows:
Price
Speed
Reliability
Extras

Columns: Most Important, 2nd Most Important, 3rd Most Important

If Speed is picked in column 1 then it can't be picked in columns 2 or 3

Please Log in to join the conversation.

More
5 years 10 months ago - 5 years 10 months ago #57467 by paulfiner
Here's what I have at the moment





So each column must only have one answer and each row should have only one answer too.
Attachments:
Last Edit: 5 years 10 months ago by paulfiner.

Please Log in to join the conversation.

More
5 years 10 months ago - 5 years 10 months ago #57475 by tpartner
Add this script to the source of the question text or help. Replace "QQ" with your question ID.

The script puts a listener on the answer cells. When one is clicked, if there are any others with the same class (same column) that have a checked radio, an alert is popped up and the radio is unchecked.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		var qID = QQ;
 
		$('#question'+qID+' table.question tbody td').click(function () { 
			var cellClass = $(this).attr('class');
			var parent = $(this).parent();
			setTimeout(function() { 
				if($('.'+cellClass+' input[type=radio]:checked').length > 1) {
					alert ("Can't do that!");
					$('.'+cellClass+' input[type=radio]', parent).attr('checked', false); 
				}
			}, 100);
		});
 
	});
 
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 5 years 10 months ago by tpartner.

Please Log in to join the conversation.

More
5 years 10 months ago #57479 by paulfiner
Thanks Tony!

I've just added this in and it seems to work.

Cheers

Paul

Please Log in to join the conversation.

More
5 years 10 months ago #57518 by paulfiner
Hi Tony

Is there anyway to make the clicked radiobutton that causes the error message to show to be the one that stays clicked and the original radio button to become unchecked?

If this could be done without showing the error message that would be even better!

Cheers

Paul

Please Log in to join the conversation.

More
5 years 10 months ago #57519 by tpartner
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		var qID = QQ;
 
		$('#question'+qID+' table.question tbody td').click(function () { 
		    var cellClass = $(this).attr('class');
			var parent = $(this).parent();
			setTimeout(function() { 
				if($('.'+cellClass+' input[type=radio]:checked').length > 1) {
					$('.'+cellClass+' input[type=radio]').attr('checked', false);
					$('.'+cellClass+' input[type=radio]', parent).attr('checked', true); 
				}
			}, 250);
		});
 
	});
 
</script>

I haven't had time to test in all browsers (I'm working on your drag-n-drop images)

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 years 10 months ago #57578 by paulfiner
Thanks Tony, it works great!

Cheers

Paul

Please Log in to join the conversation.

More
5 years 10 months ago #57594 by paulfiner
Spoke too soon!

It seems to be a bit erratic when clicking on the options. Sometimes it works correctly and shows the next button after choosing 3 items and other times it doesn't. When it doesn't, you need to select another option before it will show the next button.

This is in Safari on the Mac and my client picked up on it using Explorer on Windows.

Please Log in to join the conversation.

More
5 years 10 months ago #57598 by tpartner

Sometimes it works correctly and shows the next button after choosing 3 items and other times it doesn't.

I don't understand this. What do you mean by "after choosing 3 items"? The script should fire when any radio button is selected.

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 years 10 months ago #57600 by paulfiner
Sorry Tony, I have also applied the workaround here:
docs.limesurvey.org/tiki-index.php?page=...f_an_array_mandatory

To make sure the respondent can't move on until there is a choice in each of the 3 columns.

Sometimes it works correctly othertimes it doesn't.

Please Log in to join the conversation.

More
5 years 10 months ago #57603 by tpartner
So is the problem with the workaround script or the scripts from this forum topic?

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.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form