Welcome, Guest
Username: Password: Remember me

TOPIC: Create unique options in array question

Create unique options in array question 3 years 8 months ago #57449

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

Re: Create unique options in array question 3 years 8 months ago #57450

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5423
  • Thank you received: 307
  • Karma: 252
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)limesurvey.org'"
The administrator has disabled public write access.

Re: Create unique options in array question 3 years 8 months ago #57453

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

Re: Create unique options in array question 3 years 8 months ago #57464

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

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: Create unique options in array question 3 years 8 months ago #57465

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

Re: Create unique options in array question 3 years 8 months ago #57467

  • paulfiner
  • paulfiner's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 92
  • Thank you received: 1
  • Karma: 1
Here's what I have at the moment


Ranking.png



So each column must only have one answer and each row should have only one answer too.
Last Edit: 3 years 8 months ago by paulfiner.
The administrator has disabled public write access.

Re: Create unique options in array question 3 years 8 months ago #57475

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

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 3 years 8 months ago by tpartner.
The administrator has disabled public write access.

Re: Create unique options in array question 3 years 8 months ago #57479

  • paulfiner
  • paulfiner's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 92
  • Thank you received: 1
  • Karma: 1
Thanks Tony!

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

Cheers

Paul
The administrator has disabled public write access.

Re: Create unique options in array question 3 years 8 months ago #57518

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

Re: Create unique options in array question 3 years 8 months ago #57519

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

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.132 seconds
Donation Image