Welcome, Guest
Username: Password: Remember me

TOPIC: filter dropdowns in array

filter dropdowns in array 3 weeks 4 days ago #110663

  • barbacot
  • barbacot's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 12
  • Karma: 0
I have an array (I can do it simple or with numbers) where on five rows I have five elements for the user to rate. I don't want to use the rating type question - it doesn't work well and for some users is confusing.
So, I choose dropdown presentation in the array and I populate the dropdowns with numbers from one to five.

Is it possible that when a user choose in one of the dropdowns a number this number will be deleted or mark disabled from the other dropdowns in the array?
Last Edit: 3 weeks 4 days ago by barbacot. Reason: syntax
The administrator has disabled public write access.

filter dropdowns in array 3 weeks 3 days ago #110664

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4069
  • Thank you received: 748
  • Karma: 341
Have a look at this post where an array type question is used for ranking - www.limesurvey.org/en/forum/can-i-do-thi...king-question#106841.
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 weeks 3 days ago by tpartner.
The administrator has disabled public write access.

filter dropdowns in array 3 weeks 3 days ago #110670

  • barbacot
  • barbacot's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 12
  • Karma: 0
tpartner wrote:
Have a look at this post where an array type question is used for ranking - www.limesurvey.org/en/forum/can-i-do-thi...king-question#106841.

Thank you!

Just one more thing - I need to filter some rows in the array (all but the last) and I tried to use the solution provided HERE but it does not work in limesurvey 2.05

More specifically:
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function () {
 
		// Call the mandatory row function with question ID
		mandatoryRows(QQ);
 
		// A function to render all but the last rows of an array mandatory
		function mandatoryRows(qID) {
 
			var warningText = 'Please complete the highlighted rows.';
 
			// Add a mandatory class to all rows except the last one
			$('div#question'+qID+' table.question tbody[id^="javatbd"]:not(:last) tr').addClass('mandatory');
 
			// Interrupt the submit function
			$('#movenextbtn, #movesubmitbtn').click(function(){
				var fail = '';
 
				// Loop through all mandatory rows and check for answers
				$('tr.mandatory').each(function(i){
					if($('input.radio:checked', this).length < 1) {
						 $('th, td', this).css({ 'background':'pink' });
						 fail = 1;
					}
					else {
						 $('th, td', this).css({ 'background':'' });
					}
				});
 
				if(fail == 1) {
					alert (warningText);
					return false;
				}
				else {
					return true;
				}
			});
		}
	});
 
</script>

I need this because I hide some radio buttons on the last row and if the user click by mistake the hidden button it can be considered a valid answer and added to the number of array answer clicked.
The administrator has disabled public write access.

filter dropdowns in array 3 weeks 3 days ago #110671

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4069
  • Thank you received: 748
  • Karma: 341
Try this:

<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function () {
 
		// Call the mandatory row function with question ID
		mandatoryRows(QQ);
 
		// A function to render all but the last rows of an array mandatory
		function mandatoryRows(qID) {
 
			var warningText = 'Please complete the highlighted rows.';
 
			// Add a mandatory class to all rows except the last one
			$('div#question'+qID+' table.question tr[id^="javatbd"]:not(:last)').addClass('mandatory');
 
			// Interrupt the submit function
			$('#movenextbtn, #movesubmitbtn').click(function(){
				var fail = '';
 
				// Loop through all mandatory rows and check for answers
				$('tr.mandatory').each(function(i){
					if($('input.radio:checked', this).length < 1) {
						 $('th, td', this).css({ 'background':'pink' });
						 fail = 1;
					}
					else {
						 $('th, td', this).css({ 'background':'' });
					}
				});
 
				if(fail == 1) {
					alert (warningText);
					return false;
				}
				else {
					return true;
				}
			});
		}
	});
 
</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.
The following user(s) said Thank You: barbacot

filter dropdowns in array 3 weeks 3 days ago #110673

  • barbacot
  • barbacot's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 12
  • Karma: 0
tpartner wrote:
Try this:

<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function () {
 
		// Call the mandatory row function with question ID
		mandatoryRows(QQ);
 
		// A function to render all but the last rows of an array mandatory
		function mandatoryRows(qID) {
 
			var warningText = 'Please complete the highlighted rows.';
 
			// Add a mandatory class to all rows except the last one
			$('div#question'+qID+' table.question tr[id^="javatbd"]:not(:last)').addClass('mandatory');
 
			// Interrupt the submit function
			$('#movenextbtn, #movesubmitbtn').click(function(){
				var fail = '';
 
				// Loop through all mandatory rows and check for answers
				$('tr.mandatory').each(function(i){
					if($('input.radio:checked', this).length < 1) {
						 $('th, td', this).css({ 'background':'pink' });
						 fail = 1;
					}
					else {
						 $('th, td', this).css({ 'background':'' });
					}
				});
 
				if(fail == 1) {
					alert (warningText);
					return false;
				}
				else {
					return true;
				}
			});
		}
	});
 
</script>


Flawless!!!

Thank you - so it was about the 'tr' element - changed design in 2.00+...

I noticed that there are some workarounds that are not working anymore in 2.05 like manual.limesurvey.org/Workarounds:_Manip...ble_Text.29_question because of this change in design - they require some detective work with google developer tools.
Last Edit: 3 weeks 3 days ago by barbacot.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.204 seconds
Donation Image