Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:

TOPIC: Array by Column mandatory error message not working properly

Array by Column mandatory error message not working properly 5 years 6 months ago #58228

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

Array by Column mandatory error message not working properly 5 years 6 months ago #58245

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6315
  • Thank you received: 1407
  • Karma: 546
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.

Array by Column mandatory error message not working properly 5 years 6 months ago #58249

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

Array by Column mandatory error message not working properly 5 years 6 months ago #58285

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6315
  • Thank you received: 1407
  • Karma: 546
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.
The administrator has disabled public write access.

Array by Column mandatory error message not working properly 5 years 6 months ago #58288

  • paulfiner
  • paulfiner's Avatar
  • Offline
  • Expert Lime
  • Posts: 92
  • Thank you received: 1
  • Karma: 1
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
The administrator has disabled public write access.
Time to create page: 0.202 seconds
Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form