Check out the LimeSurvey source code on GitHub!

filter dropdowns in array

More
2 years 6 months ago - 2 years 6 months ago #110663 by barbacot
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: 2 years 6 months ago by barbacot. Reason: syntax

Please Log in to join the conversation.

More
2 years 6 months ago - 2 years 6 months ago #110664 by tpartner
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.
Last Edit: 2 years 6 months ago by tpartner.

Please Log in to join the conversation.

More
2 years 6 months ago #110670 by barbacot

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.

Please Log in to join the conversation.

More
2 years 6 months ago #110671 by tpartner
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.
The following user(s) said Thank You: barbacot

Please Log in to join the conversation.

More
2 years 6 months ago - 2 years 6 months ago #110673 by barbacot

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: 2 years 6 months ago by barbacot.

Please Log in to join the conversation.

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