- Posts: 10
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // Identify this question var thisQuestion = $('#question{QID}'); var currentVal = $('input.text', thisQuestion).val(); // Build an array of autocomplete items var testArr = []; $('.question-help ul:eq(0) li', thisQuestion).each(function(i) { testArr.push($(this).text()); }); // Initialise the autocomplete plugin $('input.text', thisQuestion).autocomplete({ source: testArr, minLength: 1, change: function(event, ui) { if(!ui.item){ // Nothing matched in the data array so clear the value $(this).val(''); } currentVal = $(this).val(); }, response: function(event, ui) { if($(ui.content).size() == 0){ // Nothing found in the data array so revert to last value $(this).val(currentVal); setTimeout(function() { if(currentVal != '') { $('input.text', thisQuestion).autocomplete('search'); } }, 200); } else { currentVal = $(this).val(); } } }).on('keyup', function(e) { if($.trim($(this).val()) == '') { $(this).val(''); currentVal = $(this).val(); } }); }); </script>
<script type="text/javascript" src="{TEMPLATEURL}jquery.csv.js"></script> <script> var url = "{TEMPLATEURL}docenti.csv"; $(function() { var seriesTitle = new Array(); $.get(url,function(data){ fullArray = $.csv.toArrays(data); $(fullArray).each(function(i, item){ seriesTitle.push(item[0]); }); $("#question{QID} input[type=text]").autocomplete({ source: seriesTitle }); }); }); </script>
That's what my sample survey does. Did you try it?The best would be that if the content of the field is not a value of the list (written or selected by the participant), the field becomes empty. So if I write "Aprle" instead of "Apple" the field remain empty.
tpartner wrote: That's what my sample survey does. Did you try it?
$('.survey-question-help ul:eq(0) li', thisQuestion).each(function(i) { testArr.push($(this).text()); });
Thanks Ben. It may also need to be modified for the upcoming 3.x version - let's wait until beta testing to see.For interested users, also working with 2.06/2.6 versions adapting where needed ".question-help selector"...
For me working with:
:woohoo:tpartner wrote: ...upcoming 3.x version - let's wait until beta testing to see.