- Posts: 10635
- Thank you received: 3698
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Auto-suggest text field
- tpartner
- Away
- LimeSurvey Community Team
Less
More
10 years 9 months ago #97338
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Auto-suggest text field
Code:
<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.
The topic has been locked.
- arielmosto
- Offline
- Junior Member
Less
More
- Posts: 27
- Thank you received: 0
10 years 9 months ago #97347
by arielmosto
Replied by arielmosto on topic Auto-suggest text field
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
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 topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10635
- Thank you received: 3698
10 years 9 months ago #97348
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Auto-suggest text field
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.
The following user(s) said Thank You: DenisChenu
The topic has been locked.
- arielmosto
- Offline
- Junior Member
Less
More
- Posts: 27
- Thank you received: 0
10 years 9 months ago #97349
by arielmosto
Replied by arielmosto on topic Auto-suggest text field
Dear Tony, I understand perfectly.
Thank you very much for your time, we have made a new donation to support the project.
Regards Ariel
Thank you very much for your time, we have made a new donation to support the project.
Regards Ariel
The topic has been locked.