Check out the LimeSurvey source code on GitHub!

Can I set a minimum charactors/time requirement on long free text questions?

More
5 years 4 months ago #67840 by anlie
Can I set a minimum charactors/ time spend requirement on long free text questions? I can only see the maximum charactors/ time limit requirement from the software. Thank you very much!

Please Log in to join the conversation.

More
5 years 4 months ago #67858 by Mazi
For text questions you can only set a maximum number of characters. You should be able to use regular expressions though: docs.limesurvey.org/Using+regular+expres...tions+for+LimeSurvey

Some text questions also support timers (see docs.limesurvey.org/Advanced+question+se...imeSurvey#time_limit ), but I think those timers are only used to limit the time, not to check if a certain time was spend. For this you might have to code your own Javascript function.


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
5 years 4 months ago #67879 by tpartner
Here is a JavaScript solution to enforce a minimum number of characters and a minimum elapsed time (in seconds) for a long-text question.


1) Set up your survey to use JavaScript .

2) Add the following script to the source of the long-text question. Replace "QQ" with the long-text question ID , "CC" with the minimum number of characters and "TT" with the minimum number of seconds.

The script interrupts the Next/Submit function and checks for the minimum characters and elapsed time. If either are not met, an alert is displayed and the Next/Submit function is aborted.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		minCharMinTime(QQ, CC, TT);
 
		function minCharMinTime(qID, minChars, minTime) {
 
			var startTime = new Date();
 
			$('#movenextbtn, #movesubmitbtn').click(function(){
 
				var endTime = new Date();
 
				if($('#question'+qID+' textarea').val().replace(/ /g,'').length < minChars) {
					alert ('You must enter at least '+minChars+' characters.');
					return false;
				}
				else if((endTime - startTime)/1000 <= minTime) {
					alert ('You must spend at least '+minTime+' seconds on the question.');
					return false;
				}
				else {
					return true;
				}
 
				return false;
			});
		}
 
	});
</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 4 months ago #67934 by anlie
Thank you very much for both of your reply. It's difficult to me. Hope we can have an option like this later.:lol:

Please Log in to join the conversation.

More
5 years 4 months ago #67942 by Mazi
Tony, I heard there is some place left at the workaround wiki page ;-)


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
5 years 4 months ago #67955 by tpartner
Here is the script with a small bug fixed:
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		minCharMinTime(QQ, CC, TT);
 
		function minCharMinTime(qID, minChars, minTime) {
 
			var startTime = new Date();
 
			$('#movenextbtn, #movesubmitbtn').click(function(){
 
				var endTime = new Date();
 
				if($('#question'+qID+' textarea').val().replace(/ /g,'').length < minChars) {
					alert ('You must enter at least '+minChars+' characters.');
					return false;
				}
				else if((endTime - startTime)/1000 <= minTime) {
					alert ('You must spend at least '+minTime+' seconds on the question.');
					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.

Please Log in to join the conversation.

More
5 years 4 months ago #67958 by tpartner

...I heard there is some place left at the workaround wiki page...


I think it would be rare that both the minimum time and minimum characters would be required so I broke it up into two workarounds:

Minimum elapsed time before moving forward in survey - docs.limesurvey.org/tiki-index.php?page_...ng_forward_in_survey

Minimum number of characters in Long free text or Huge free text questions - docs.limesurvey.org/tiki-index.php?page_..._free_text_questions

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.

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