Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:

THEMA: Auto-suggest text field

Re: Auto-suggest text field 1 Jahr 5 Monate her #97270

  • tpartner
  • tpartners Avatar
  • ONLINE
  • LimeSurvey Team
  • Beiträge: 4372
  • Dank erhalten: 830
  • Karma: 381
Yeah, but when would you want this alert to pop up? Every time the respondent types something or every time the list appears?
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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Auto-suggest text field 1 Jahr 5 Monate her #97272

  • arielmosto
  • arielmostos Avatar
  • OFFLINE
  • Junior Lime
  • Beiträge: 29
  • Karma: 0
Tony:

Alert pop up should appear when the respondent writes an option out of the list.

The list contains the 200 largest firms in an industry (complex and lengthy names with many words)*. Not much chance of entering new, but the possibility of ranking must be free, it should be possible to choose one from the list or a new company.

Thanks for your time and all your ideas and experience are welcome. Ariel

*The names on the list are very similar to each other, such as:
  • Red Hot Chili Peppers Inc.
  • Blue Hot Chili Peppers Corp.
  • Red cold Chili brothers
Letzte Änderung: 1 Jahr 5 Monate her von arielmosto. Begründung: clarification
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Auto-suggest text field 1 Jahr 5 Monate her #97282

  • tpartner
  • tpartners Avatar
  • ONLINE
  • LimeSurvey Team
  • Beiträge: 4372
  • Dank erhalten: 830
  • Karma: 381
Try this code in the question source:
<script type="text/javascript" charset="utf-8">	
	$(document).ready(function() {
 
		// Identify the question
		var q1ID = '{QID}';
		var q1 = $('#question'+q1ID+'');
 
		var url = 'http://localhost/limesurvey2/upload/templates/test_csv_2/countries.csv';
		//var url = '{TEMPLATEURL}companies.csv';
		var countries = new Array();
 
		// Grab the CSV contents
		$.get(url, function(data) {
 
			// Convert CSV contents to an array of arrays
			tmp = $.csv.toArrays(data);
 
			// Load the countries array
			$(tmp).each(function(i, item) {
				countries.push(item[0]);
			});
 
			var msg = 'You cannot have duplicate entries.';
			var msg2 = 'If your option is in the list, please use the mouse to select it. If not, write it.';
 
			$('input.text', q1).autocomplete({
				source: countries,
				minLength: 0,
				change: function(event, ui) {
					var thisInput = $(this);
					var duplicateError = false;
					if($(thisInput).val() != '') {
						// Check for duplicates
						$('input.text', q1).not($(thisInput)).each(function(){
							if($(this).val().toLowerCase() == $(thisInput).val().toLowerCase()) {
								alert (msg);
								duplicateError = true;
								$(thisInput).val('').focus();
								$('input.text', q1).autocomplete('close');
								return false;
							}
						});
						if(duplicateError == true) {
							return;
						}
						// Check if entered value is in the list
						var inList = false;
						$(countries).each(function(){
							if(this.toLowerCase() == $(thisInput).val().toLowerCase()) {
								inList = true;
							}
						});
						if(inList == false) {
							alert (msg2);
						}
					}
				},
				select: function(event, ui) {
					// Check for duplicates
					var thisInput = $(this);
					var okay = 1;
					$('input.text', q1).not($(thisInput)).each(function(){
						if($(this).val().toLowerCase() == ui.item.value.toLowerCase()) {
							okay = 0;
						}
					});
					if(okay == 0) {
						alert (msg);
						return false;
					}
				} 			
			});	
		});	
	});
</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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Auto-suggest text field 1 Jahr 5 Monate her #97290

  • arielmosto
  • arielmostos Avatar
  • OFFLINE
  • Junior Lime
  • Beiträge: 29
  • Karma: 0
Thanks Tony.

The msg2 not displayed when you write an option out of the list.

Below this
if(inList == false) {
							alert (msg2);
I add
return false;

And it works, when changing cell with the mouse, but not work with the keyboard, with "Tab"

Perhaps "return false" is not sufficiently good to work properly in this case.

Thanks ! Ariel
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Auto-suggest text field 1 Jahr 5 Monate her #97294

  • arielmosto
  • arielmostos Avatar
  • OFFLINE
  • Junior Lime
  • Beiträge: 29
  • Karma: 0
Tony;

I just checked again and the code works correctly.

"msg2" is displayed by clicking with the mouse but not with Tab.

Is it possible to do that with Tab works well?

Regards ! Ariel
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Auto-suggest text field 1 Jahr 5 Monate her #97319

  • arielmosto
  • arielmostos Avatar
  • OFFLINE
  • Junior Lime
  • Beiträge: 29
  • Karma: 0
Tony:

We are planning to leave the possibility of advancing with the keyboard button "Tab" for those not listed.

On the other hand, we tried the script in the question type "Array (Texts)" and fail to make it work.

You can make it work for "Array (texts)"?

Here its the image from question Array:


Anhang Pantallazo-1.png nicht gefunden



Thanks !
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Auto-suggest text field 1 Jahr 5 Monate her #97338

  • tpartner
  • tpartners Avatar
  • ONLINE
  • LimeSurvey Team
  • Beiträge: 4372
  • Dank erhalten: 830
  • Karma: 381
<script type="text/javascript" charset="utf-8">	
	$(document).ready(function() {
 
		// Identify the question
		var q1ID = '{QID}';
		var q1 = $('#question'+q1ID+'');
 
		var url = 'http://localhost/limesurvey2/upload/templates/test_csv_2/countries.csv';
		//var url = '{TEMPLATEURL}companies.csv';
		var countries = new Array();
 
		// Grab the CSV contents
		$.get(url, function(data) {
 
			// Convert CSV contents to an array of arrays
			tmp = $.csv.toArrays(data);
 
			// Load the countries array
			$(tmp).each(function(i, item) {
				countries.push(item[0]);
			});
 
			var msg = 'You cannot have duplicate entries.';
			var msg2 = 'If your option is in the list, please use the mouse to select it. If not, write it.';
 
			$('input[type="text"]', q1).autocomplete({
				source: countries,
				minLength: 0,
				change: function(event, ui) {
					var thisInput = $(this);
					var duplicateError = false;
					if($(thisInput).val() != '') {
						// Check for duplicates
						$('input[type="text"]', q1).not($(thisInput)).each(function(){
							if($(this).val().toLowerCase() == $(thisInput).val().toLowerCase()) {
								alert (msg);
								duplicateError = true;
								$(thisInput).val('').focus();
								$('input[type="text"]', q1).autocomplete('close');
								return false;
							}
						});
						if(duplicateError == true) {
							return;
						}
						// Check if entered value is in the list
						var inList = false;
						$(countries).each(function(){
							if(this.toLowerCase() == $(thisInput).val().toLowerCase()) {
								inList = true;
							}
						});
						if(inList == false) {
							alert (msg2);
						}
					}
				},
				select: function(event, ui) {
					// Check for duplicates
					var thisInput = $(this);
					var okay = 1;
					$('input[type="text"]', q1).not($(thisInput)).each(function(){
						if($(this).val().toLowerCase() == ui.item.value.toLowerCase()) {
							okay = 0;
						}
					});
					if(okay == 0) {
						alert (msg);
						return false;
					}
				} 			
			});	
		});	
	});
</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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Auto-suggest text field 1 Jahr 5 Monate her #97347

  • arielmosto
  • arielmostos Avatar
  • OFFLINE
  • Junior Lime
  • Beiträge: 29
  • Karma: 0
Dear Tony, thank you very much.

It works but it was a small detail pending; duplicate validation should work in this type of question, per row (first, second and third ranking)

No per column, it does not allow ranking, the same company in two different sectors.

Regards! Ariel
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Auto-suggest text field 1 Jahr 5 Monate her #97348

  • tpartner
  • tpartners Avatar
  • ONLINE
  • LimeSurvey Team
  • Beiträge: 4372
  • Dank erhalten: 830
  • Karma: 381
Sorry, I've already spent WAY too much time on this post. Perhaps someone els can help you.
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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Folgende Benutzer bedankten sich: DenisChenu

Re: Auto-suggest text field 1 Jahr 5 Monate her #97349

  • arielmosto
  • arielmostos Avatar
  • OFFLINE
  • Junior Lime
  • Beiträge: 29
  • Karma: 0
Dear Tony, I understand perfectly.

Thank you very much for your time, we have made a new donation to support the project.

Regards Ariel
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Moderatoren: ITEd
Ladezeit der Seite: 0.173 Sekunden
Donation Image