Welcome, Guest
Username: Password: Remember me

TOPIC: Auto-suggest text field

Re: Auto-suggest text field 1 year 4 months ago #97270

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4293
  • Thank you received: 810
  • Karma: 373
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.
The administrator has disabled public write access.

Re: Auto-suggest text field 1 year 4 months ago #97272

  • arielmosto
  • arielmosto's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 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
Last Edit: 1 year 4 months ago by arielmosto. Reason: clarification
The administrator has disabled public write access.

Re: Auto-suggest text field 1 year 4 months ago #97282

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4293
  • Thank you received: 810
  • Karma: 373
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.
The administrator has disabled public write access.

Re: Auto-suggest text field 1 year 4 months ago #97290

  • arielmosto
  • arielmosto's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 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
The administrator has disabled public write access.

Re: Auto-suggest text field 1 year 4 months ago #97294

  • arielmosto
  • arielmosto's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 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
The administrator has disabled public write access.

Re: Auto-suggest text field 1 year 4 months ago #97319

  • arielmosto
  • arielmosto's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 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:


Attachment Pantallazo-1.png not found



Thanks !
The administrator has disabled public write access.

Re: Auto-suggest text field 1 year 4 months ago #97338

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4293
  • Thank you received: 810
  • Karma: 373
<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.
The administrator has disabled public write access.

Re: Auto-suggest text field 1 year 4 months ago #97347

  • arielmosto
  • arielmosto's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 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
The administrator has disabled public write access.

Re: Auto-suggest text field 1 year 4 months ago #97348

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4293
  • Thank you received: 810
  • Karma: 373
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.
The administrator has disabled public write access.
The following user(s) said Thank You: DenisChenu

Re: Auto-suggest text field 1 year 4 months ago #97349

  • arielmosto
  • arielmosto's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 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
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.148 seconds
Donation Image