Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:

THEMA: Validation of multiple choice with comments

Validation of multiple choice with comments 9 Monate 2 Wochen her #109937

  • rauno_s
  • rauno_ss Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 16
  • Dank erhalten: 6
  • Karma: 2
Hi,

can anybody help (or point to an example) of how to validate a mandatory multiple-choice-with-comment type of question. Expression should validate that all checked options must have something (at least 5 characters) typed in the comment field.

thanks!
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Validation of multiple choice with comments 9 Monate 2 Wochen her #110002

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4632
  • Dank erhalten: 925
  • Karma: 408
I'm not sure you can do that with Expression Manager but you can with JavaScript.

Set up your survey to use JavaScript and add something like this to the source of the question:

<script type="text/javascript" charset="utf-8">	
	$(document).ready(function() {
 
		// Identify this question
		var thisQuestion = $('#question'+{QID}+'');
 
		// Interrupt the submit process
		$('#movenextbtn, #movesubmitbtn').bind('click', function () {
 
			// Reset the errors
			var commentError = 0;
			$('li.answer-item', thisQuestion).css('background-color', 'transparent');
 
			// Check for invalid comments
			$('input.checkbox:checked', thisQuestion).each(function(i) {
				var thisItem = $(this).closest('li.answer-item');
				var thisComment = $('input[type="text"]', thisItem);
				if($(thisComment).val().length < 6) {
					$(thisItem).css('background-color', 'pink');
					commentError = 1;
				}
			});
 
			// Comment failed so abort submit
			if(commentError == 1) {
				alert("Comments must be at least 5 characters.");
				return false;
			}
		});
 
	});
</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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Moderatoren: ITEd
Ladezeit der Seite: 0.134 Sekunden
Donation Image