Check out the LimeSurvey source code on GitHub!

Prefilling text field from token?

More
5 years 4 months ago #66529 by Mazi
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)survey-consulting.com'"

Please Log in to join the conversation.

More
5 years 4 months ago #66533 by waitz

Version 1.91+ Build 11232 | PHP 5.3.9 | MySQL 5.1.56 |

Please Log in to join the conversation.

More
5 years 4 months ago - 5 years 4 months ago #66537 by tpartner
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.
Last Edit: 5 years 4 months ago by tpartner.

Please Log in to join the conversation.

More
5 years 4 months ago #66539 by waitz
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...5432.lss
File Size:21 KB

Version 1.91+ Build 11232 | PHP 5.3.9 | MySQL 5.1.56 |
Attachments:

Please Log in to join the conversation.

More
5 years 4 months ago #66541 by tpartner
You need to replace "QQ" with the question ID, not the whole SGQA.



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.
Attachments:

Please Log in to join the conversation.

More
5 years 4 months ago #66542 by waitz
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 |

Please Log in to join the conversation.

More
5 years 4 months ago #66545 by tpartner
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.

Please Log in to join the conversation.

More
5 years 4 months ago - 5 years 4 months ago #66557 by waitz
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: 5 years 4 months ago by waitz.

Please Log in to join the conversation.

More
5 years 4 months ago #66561 by tpartner
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.

Please Log in to join the conversation.

More
5 years 4 months ago #66566 by waitz
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 |

Please Log in to join the conversation.

More
5 years 4 months ago - 5 years 4 months ago #66572 by waitz
There is an interesting thing that happens with the javascript warning:

If you forget a field, press Next, get the javascript warning (correct), then press the Previous button (for some reason).

What happens then is that both Next and Previous stop working and you cannot continue in the survey...

See the screen shot video: www.screencast-o-matic.com/watch/cX6VoHZM1

Version 1.91+ Build 11232 | PHP 5.3.9 | MySQL 5.1.56 |
Last Edit: 5 years 4 months ago by waitz.

Please Log in to join the conversation.

More
5 years 4 months ago #66575 by Mazi

waitz wrote: There is an interesting thing that happens with the javascript warning:

If you forget a field, press Next, get the javascript warning (correct), then press the Previous button (for some reason).

What happens then is that both Next and Previous stop working and you cannot continue in the survey...

See the screen shot video: www.screencast-o-matic.com/watch/cX6VoHZM1

Please test if the problem still exists at the latest release . If so please open a ticket at the Bugtracker and...
  1. Give as much information as possible
  2. Attach your survey. You can mark your ticket "private" so that only the developers will be able to take a look at it.
  3. Provide step-by-step instructions how to reproduce the problem.
  4. If possible/helpful please provide screenshots

Afterwards please post the link to the Bugtracker so we can follow the progress.

Thanks!


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 #66578 by waitz
OK, will do!

Version 1.91+ Build 11232 | PHP 5.3.9 | MySQL 5.1.56 |

Please Log in to join the conversation.

More
5 years 4 months ago #66580 by waitz
Hmmm. I have made quite a few changes in my limesurvey.

Does the comfort updater from 1.91+ 10494 to 11026 change a lot of files? Or is there an overview of which files it changes, so that I know where I have to repeat my changes?

Version 1.91+ Build 11232 | PHP 5.3.9 | MySQL 5.1.56 |

Please Log in to join the conversation.

More
5 years 4 months ago #66581 by waitz
I have put in a bug report

Version 1.91+ Build 11232 | PHP 5.3.9 | MySQL 5.1.56 |

Please Log in to join the conversation.

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