Welcome, Guest
Username: Password: Remember me

TOPIC: Prefilling text field from token?

Re: Prefilling text field from token? 2 years 10 months ago #66529

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5302
  • Thank you received: 291
  • Karma: 247
Which test survey?


Another tip: When enabling this feature you can see all codes at the printable survey feature:
"$showsgqacode: (>1.91) This setting is used at the printable survey feature Image and defaults to false. If you set $showsgqacode = true; the IDs for each question - and answer if applicable - will be shown; these IDs match the column heading at the Lime_survey_12345 table which holds the answer data for a certain survey. These Ids can be used for a code book for manual database queries."
source: docs.limesurvey.org/Optional+settings&st...nd_Response_Browsing

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Re: Prefilling text field from token? 2 years 10 months ago #66533

  • waitz
  • waitz's Avatar
  • OFFLINE
  • Gold Lime
  • Posts: 171
  • Thank you received: 1
  • Karma: 3
The demo at: www.partnersinc.biz/surveys//index.php?s...42&newtest=Y&lang=en

But it is possible not yours?
Version 1.91+ Build 11232 | PHP 5.3.9 | MySQL 5.1.56 |
The administrator has disabled public write access.

Re: Prefilling text field from token? 2 years 10 months ago #66537

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4071
  • Thank you received: 748
  • Karma: 341
Here is a simplified version of the workaround that tests all inputs of a multiple-text or multiple-numeric question for values. If any input is found empty, an alert is popped up and the Next/Submit function is aborted.

Replace "QQ" with the question ID.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function () {
 
		// Interrupt the submit function
		$('form#limesurvey').submit(function () {
			// Override the built-in "disable navigation buttons" feature
			$('#moveprevbtn, #movenextbtn, #movesubmitbtn').attr('disabled', '');
 
			var empty = 0;
 
			var warningText = 'Please complete the highlighted inputs.';
 
			// Call the mandatory row function with question ID
			mandatoryRow(QQ);
 
			// A function to render rows of an array mandatory
			function mandatoryRow(qID) {
 
				$('div#question' + qID + ' input.text').each(function (i) {
					if ($(this).val() == '') {
						$(this).css('background-color', 'pink');
						empty = 1;
					} else {
						$(this).css('background-color', '#FFFFFF');
					}
				});
			}
 
			if (empty == 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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 2 years 10 months ago by tpartner.
The administrator has disabled public write access.

Re: Prefilling text field from token? 2 years 10 months ago #66539

  • waitz
  • waitz's Avatar
  • OFFLINE
  • Gold Lime
  • Posts: 171
  • Thank you received: 1
  • Karma: 3
Thanks for the input Tony, but for some reason I can't make it work...
On submit I get an new error, which I am not sure what is about:
Notice: Undefined variable: value in .../common_functions.php on line 6484
Warning: Invalid argument supplied for foreach() in .../index.php on line 3224
Warning: Invalid argument supplied for foreach() in .../index.php on line 3247
In the attached test survey I have 3 sub questions, and only 2 of them I would like to be mandatory. Then it would be complete.
Hmmm....

File Attachment:

File Name: limesurvey_survey_65432.lss
File Size: 21 KB
Version 1.91+ Build 11232 | PHP 5.3.9 | MySQL 5.1.56 |
The administrator has disabled public write access.

Re: Prefilling text field from token? 2 years 10 months ago #66541

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4071
  • Thank you received: 748
  • Karma: 341
You need to replace "QQ" with the question ID, not the whole SGQA.

Capture_2011-09-30.PNG


Here is the script modified to make rows 1 and 3 mandatory:
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function () {
 
		// Interrupt the submit function
		$('form#limesurvey').submit(function () {
			// Override the built-in "disable navigation buttons" feature
			$('#moveprevbtn, #movenextbtn, #movesubmitbtn').attr('disabled', '');
 
			var empty = 0;
 
			var warningText = 'Please complete the highlighted inputs.';
 
			// Call the mandatory row function with question ID
			mandatoryRow(QQ, 1);
			mandatoryRow(QQ, 3);
 
			// A function to render rows of an array mandatory
			function mandatoryRow(qID, rowNum) {
 
				if ($('div#question'+ qID+ ' input.text:eq('+Number(rowNum - 1)+')').val() == '') {
					$('div#question'+ qID+ ' input.text:eq('+Number(rowNum - 1)+')').css('background-color', 'pink');
					empty = 1;
				} else {
					$('div#question'+ qID+ ' input.text:eq('+Number(rowNum - 1)+')').css('background-color', '#FFFFFF');
				}
			}
 
			if (empty == 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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Prefilling text field from token? 2 years 10 months ago #66542

  • waitz
  • waitz's Avatar
  • OFFLINE
  • Gold Lime
  • Posts: 171
  • Thank you received: 1
  • Karma: 3
Ahh, sweet. Now I see, and it works. Yoohoo!

Any idea what my errors are about?
Version 1.91+ Build 11232 | PHP 5.3.9 | MySQL 5.1.56 |
The administrator has disabled public write access.

Re: Prefilling text field from token? 2 years 10 months ago #66545

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4071
  • Thank you received: 748
  • Karma: 341
Sorry, no I don't and I didn't get them when I ran your survey on my installation.
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.
The administrator has disabled public write access.

Re: Prefilling text field from token? 2 years 10 months ago #66557

  • waitz
  • waitz's Avatar
  • OFFLINE
  • Gold Lime
  • Posts: 171
  • Thank you received: 1
  • Karma: 3
I started to work on a new survey, and then I don't get the error either.

The last crux I think I have is to see if I can make a variant of the script below for a different question, that makes it required that minimum one of the fields are filled in (not row 1 & 3, but minimum 1 of the 3)
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function () {
 
		// Interrupt the submit function
		$('form#limesurvey').submit(function () {
			// Override the built-in "disable navigation buttons" feature
			$('#moveprevbtn, #movenextbtn, #movesubmitbtn').attr('disabled', '');
 
			var empty = 0;
 
			var warningText = 'Please complete the highlighted inputs.';
 
			// Call the mandatory row function with question ID
			mandatoryRow(QQ, 1);
			mandatoryRow(QQ, 3);
 
			// A function to render rows of an array mandatory
			function mandatoryRow(qID, rowNum) {
 
				if ($('div#question'+ qID+ ' input.text:eq('+Number(rowNum - 1)+')').val() == '') {
					$('div#question'+ qID+ ' input.text:eq('+Number(rowNum - 1)+')').css('background-color', 'pink');
					empty = 1;
				} else {
					$('div#question'+ qID+ ' input.text:eq('+Number(rowNum - 1)+')').css('background-color', '#FFFFFF');
				}
			}
 
			if (empty == 1) {
				alert(warningText);
				return false;
			} else {
				return true;
			}
		});
	});
 
</script>
Version 1.91+ Build 11232 | PHP 5.3.9 | MySQL 5.1.56 |
Last Edit: 2 years 10 months ago by waitz.
The administrator has disabled public write access.

Re: Prefilling text field from token? 2 years 10 months ago #66561

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4071
  • Thank you received: 748
  • Karma: 341
The following will require a minimum number of sub-questions in a multi-text to be answered. Replace "QQ" with the question ID and "NN" with the mininum number of sub-questions to be required.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function () {
 
		// Call the minimum answers function with question ID and minimum required inputs
		minInputs(QQ, NN);
 
		// A function to make a mininum number of inputs mandatory
		function minInputs(qID, minNum) {
 
			var warningText = 'Please fill in at least '+minNum+' input(s).';
 
			// Interrupt the submit function
			$('form#limesurvey').submit(function () {
				// Override the built-in "disable navigation buttons" feature
				$('#moveprevbtn, #movenextbtn, #movesubmitbtn').attr('disabled', '');
 
				var numEntered = 0;
 
				// Loop through the inputs
				$('#question'+ qID+ ' input.text').each(function(i){
					if($(this).val() != '') {
						numEntered++;
						$(this).removeClass('emptyInput');
					}
					else {
						$(this).addClass('emptyInput');
					}
				});
 
				if (numEntered < minNum) {
					$('#question'+ qID+ ' .emptyInput').css({'background':'pink'});
					alert(warningText);
					return false;
				}
				else {
					$('#question'+ qID+ ' input.text').css({'background':''}).removeClass('emptyInput');
					return true;
				}
			});
		}
	});
</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.
The administrator has disabled public write access.

Re: Prefilling text field from token? 2 years 9 months ago #66566

  • waitz
  • waitz's Avatar
  • OFFLINE
  • Gold Lime
  • Posts: 171
  • Thank you received: 1
  • Karma: 3
WOW :laugh:

By using these scripts I can drastically reduce the conditions complexity, and amount of questions.

Thanks again
Version 1.91+ Build 11232 | PHP 5.3.9 | MySQL 5.1.56 |
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.365 seconds
Donation Image