- Posts: 89
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<link href="/upload/surveys/{SID}/files/jquery-ui.min.css" rel="stylesheet" type="text/css" /> <script src="/upload/surveys/{SID}/files/jquery-ui.min.js"></script> <script src="/upload/surveys/{SID}/files/jquery.csv.min.js"></script> <script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:complete',function() { // Identify this question var thisQuestion = $('#question{QID}'); // Hide the second input $('.question-item:eq(1)', thisQuestion).hide(); var url = "/upload/surveys/{SID}/files/NAMES_cleaned.csv"; var Names = []; var Coords = { }; $.get(url, function(data){ fullArray = $.csv.toArrays(data); $(fullArray).each(function(i, item){ Names.push(item[0]); Coords[item[0].toLowerCase()] = item[1]; }); // Initiate the Autocomplete plugin $('input[type=text]:eq(0)', thisQuestion).autocomplete({ minLength: 2, source: Names, select: function(event, ui) { $('input[type=text]:eq(1)', thisQuestion).val(Coords[ui.item.value.toLowerCase()].replace(/;/, ' ')); } }).on('change', function(e) { $('input[type=text]:eq(1)', thisQuestion).val(Coords[$.trim($(this).val()).toLowerCase()].replace(/;/, ' ')); }); }); }); </script>
Try this (untested):Is it possible that after the selection for the autocompletion, the NEXT is button is automatically clicked to immediately display the map which is in the next question?
<link href="/upload/surveys/{SID}/files/jquery-ui.min.css" rel="stylesheet" type="text/css" /> <script src="/upload/surveys/{SID}/files/jquery-ui.min.js"></script> <script src="/upload/surveys/{SID}/files/jquery.csv.min.js"></script> <script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:complete',function() { // Identify this question var thisQuestion = $('#question{QID}'); // Hide the second input $('.question-item:eq(1)', thisQuestion).hide(); var url = "/upload/surveys/{SID}/files/NAMES_cleaned.csv"; var Names = []; var Coords = { }; $.get(url, function(data){ fullArray = $.csv.toArrays(data); $(fullArray).each(function(i, item){ Names.push(item[0]); Coords[item[0].toLowerCase()] = item[1]; }); // Initiate the Autocomplete plugin $('input[type=text]:eq(0)', thisQuestion).autocomplete({ minLength: 2, source: Names, select: function(event, ui) { $('input[type=text]:eq(1)', thisQuestion).val(Coords[ui.item.value.toLowerCase()].replace(/;/, ' ')); // Auto-submit if($.trim($('input[type=text]:eq(1)', thisQuestion).val()) != '') { $('#ls-button-submit').trigger('click'); } } }).on('change', function(e) { $('input[type=text]:eq(1)', thisQuestion).val(Coords[$.trim($(this).val()).toLowerCase()].replace(/;/, ' ')); // Auto-submit if($.trim($('input[type=text]:eq(1)', thisQuestion).val()) != '') { $('#ls-button-submit').trigger('click'); } }); }); }); </script>
Try this hack (in this example, the location question has code "Q1" and the coordinates sub-question has code "SQ002").Is it possible to have it equally drawn for openstreetmap, now its not the case?
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:complete',function() { var latLong = '{Q1_SQ002}'.split(' '); setTimeout(function() { $('#answer_lat{SGQ}_c').val($.trim(latLong[0])); $('#answer_lng{SGQ}_c').val($.trim(latLong[1])).trigger('blur'); }, 1000); }); </script>