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 #66419

  • waitz
  • waitz's Avatar
  • Offline
  • Gold Lime
  • Posts: 171
  • Thank you received: 1
  • Karma: 3
Can I prefill a short text input-field with token values?

I can enter a token value in the answer prefix and answer suffix, but not in the text field itself.

I have been hoping for this feature for a long time ;) Is it possible now in 1.91?
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 #66422

  • Mazi
  • Mazi's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 5843
  • Thank you received: 348
  • Karma: 261
There is a workaround fr this at docs.limesurvey.org/Workarounds%3A+Manip..._personalized_limit_ (only the first code snippet applies).
Also search the forum, I think I have seen other examples there.

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 #66461

  • waitz
  • waitz's Avatar
  • Offline
  • Gold Lime
  • Posts: 171
  • Thank you received: 1
  • Karma: 3
Hmmm, it says it is for a Multiple numerical input. I tried to enter this piece into the question of the short text field:
<script type="text/javascript" charset="utf-8">
function Custom_On_Load(){ 
   document.getElementById('answer1000X10X11').value='{TOKEN:ATTRIBUTE_1}'; 
   document.getElementById('answer1000X10X11').readOnly=1; 
} 
</script>
And changed it to:
<script type="text/javascript" charset="utf-8">
function Custom_On_Load(){ 
   document.getElementById('answer64197X8X71').value='{TOKEN:FIRSTNAME}'; 
   document.getElementById('answer64197X8X71').readOnly=1; 
} 
</script>
I actually searched in the forum for quite a while, but I couldn't find anything similar. Maybe I search for the wrong thing..
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 #66496

  • waitz
  • waitz's Avatar
  • Offline
  • Gold Lime
  • Posts: 171
  • Thank you received: 1
  • Karma: 3
Ahh, look and thou shall find: www.limesurvey.org/forum/can-i-do-this-w...-table?lang=en#64477

The only thing is: when the 'multiple short text' are required fields, and the user misses one, then all fields are reset to original on submit. Is this possible to avoid?
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 #66499

  • Mazi
  • Mazi's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 5843
  • Thank you received: 348
  • Karma: 261
I think the best solution is to set the question to be not mandatory.

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 #66513

  • waitz
  • waitz's Avatar
  • Offline
  • Gold Lime
  • Posts: 171
  • Thank you received: 1
  • Karma: 3
Mmm, I see it is as a workaround, although not so solid.

Would it be possible to use a script to define different subquestions to be required or not required?

Or to ensure a minimum number of possible answers, like we can in multiple choice with comments?
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 #66516

  • Mazi
  • Mazi's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 5843
  • Thank you received: 348
  • Karma: 261
Sorry, both isn't possible. The solution would be to write your own Javascript mandatory validation for this question.

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 #66518

  • waitz
  • waitz's Avatar
  • Offline
  • Gold Lime
  • Posts: 171
  • Thank you received: 1
  • Karma: 3
I was afraid so ;)

I found one for array rows. Are they very different from sub questions?
docs.limesurvey.org/tiki-index.php?page=...f_an_array_mandatory
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 #66519

  • Mazi
  • Mazi's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 5843
  • Thank you received: 348
  • Karma: 261
You'd have to compare the IDs of the fields at the Demo survey (www.partnersinc.biz/surveys//index.php?s...42&newtest=Y&lang=en) with your fields. I recommend using Firefox add-on Firebug which gives you the HTML details to a field by simply clicking on it. That makes it very comfortable to check the source code.

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 #66526

  • waitz
  • waitz's Avatar
  • Offline
  • Gold Lime
  • Posts: 171
  • Thank you received: 1
  • Karma: 3
Interesting. I can probably use it by putting the sub-questions in x-scale and just one in the y-scale.

I looked with Firebug, and I could recognize some code, but it is more difficult to see where the script starts and where it ends... Would it be possible to see the actual test survey?
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 #66529

  • Mazi
  • Mazi's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 5843
  • Thank you received: 348
  • 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: 5419
  • Thank you received: 1155
  • Karma: 480
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: 5419
  • Thank you received: 1155
  • Karma: 480
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.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 1.401 seconds