Check out the LimeSurvey source code on GitHub!

Array by Column mandatory error message not working properly

More
5 years 11 months ago #58228 by paulfiner
I have an Array by Column question with 4 columns and the user must select an answer in each column. If they leave a column blank and click Next then the red error message highlights all 4 columns, and not just the one they missed.

It's not a major issue but my client has picked up on it.

Cheers

Paul

Please Log in to join the conversation.

More
5 years 11 months ago #58245 by tpartner

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 11 months ago #58249 by paulfiner
Hi Tony

I can see this working for an array question but I have an Array by Column question.
I need to check for an answer in each of my 4 columns, not by row.

I'll have a look at the javascript and see if I can adapt it to my needs.

Cheers

Paul

Please Log in to join the conversation.

More
5 years 11 months ago #58285 by tpartner
Ah, try this. (replace "QQ" with your array question ID)
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function(){
 
		mandatoryCol(QQ);
 
		function mandatoryCol(qID) {
 
			var msg = 'Please select an item in each column.';
 
			// Interrupt next/submit function
			$('form#limesurvey').submit(function(){
 
				var advance = 0;
 
				// Add column-specific classnames to radio cells
				$('#question'+qID+' table.question tbody tr').each(function(i) {
					$('td', this).each(function(i) {
						$(this).addClass('ansCol'+Number(i+1));
					});
				});
 
				$('#question'+qID+' table.question thead th').each(function(i) {
					// Add column-specific classnames to header cells
					var newClass = 'ansCol'+Number(i+1);
					$(this).addClass(newClass);
 
					// Count checked radios in each column - set flag if none found
					if ($('#question'+qID+' td.'+newClass+' input.radio:checked').length == 0) {
						advance = 1;
						$('.'+newClass).css({'background': 'pink'});
					}
					else {
						$('.'+newClass).css({'background': ''});
					}
				});
 
				// If flag set, alert and cancel next/submit
				if(advance == 1) {
					alert (msg);
					return false;
				}
				// Otherwise, carry on with next/submit
				else {
					return true;
				}
			});
		}
 
	});
 
</script>

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 11 months ago #58288 by paulfiner
Just in the nick of time!

I had just explained to the client that I couldn't get this working using my limited Javascript skills and was about to go live with the survey.
You script worked fine.

Thanks a million Tony, as ever!

Cheers

Paul

Please Log in to join the conversation.

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