Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: Prefilling text field from token?

Prefilling text field from token? 4 years 4 months ago #66529

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5840
  • Thank you received: 347
  • Karma: 261
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.

Prefilling text field from token? 4 years 4 months ago #66533

  • waitz
  • waitz's Avatar
  • Offline
  • Gold Lime
  • Posts: 171
  • Thank you received: 1
  • Karma: 3
Version 1.91+ Build 11232 | PHP 5.3.9 | MySQL 5.1.56 |
The administrator has disabled public write access.

Prefilling text field from token? 4 years 4 months ago #66537

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5408
  • Thank you received: 1154
  • Karma: 479
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: 4 years 4 months ago by tpartner.
The administrator has disabled public write access.

Prefilling text field from token? 4 years 4 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...5432.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.

Prefilling text field from token? 4 years 4 months ago #66541

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5408
  • Thank you received: 1154
  • Karma: 479
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.

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

Prefilling text field from token? 4 years 4 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.

Prefilling text field from token? 4 years 4 months ago #66545

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5408
  • Thank you received: 1154
  • Karma: 479
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.

Prefilling text field from token? 4 years 4 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: 4 years 4 months ago by waitz.
The administrator has disabled public write access.

Prefilling text field from token? 4 years 4 months ago #66561

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5408
  • Thank you received: 1154
  • Karma: 479
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.

Prefilling text field from token? 4 years 4 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.

Prefilling text field from token? 4 years 4 months ago #66572

  • waitz
  • waitz's Avatar
  • Offline
  • Gold Lime
  • Posts: 171
  • Thank you received: 1
  • Karma: 3
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: 4 years 4 months ago by waitz.
The administrator has disabled public write access.

Prefilling text field from token? 4 years 4 months ago #66575

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5840
  • Thank you received: 347
  • Karma: 261
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)limesurvey.org'"
The administrator has disabled public write access.

Prefilling text field from token? 4 years 4 months ago #66578

  • waitz
  • waitz's Avatar
  • Offline
  • Gold Lime
  • Posts: 171
  • Thank you received: 1
  • Karma: 3
OK, will do!
Version 1.91+ Build 11232 | PHP 5.3.9 | MySQL 5.1.56 |
The administrator has disabled public write access.

Prefilling text field from token? 4 years 4 months ago #66580

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

Prefilling text field from token? 4 years 4 months ago #66581

  • waitz
  • waitz's Avatar
  • Offline
  • Gold Lime
  • Posts: 171
  • Thank you received: 1
  • Karma: 3
I have put in a bug report
Version 1.91+ Build 11232 | PHP 5.3.9 | MySQL 5.1.56 |
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.606 seconds