Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

jQuery Autocomplete

  • g3guy
  • g3guy's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
10 years 21 hours ago #106446 by g3guy
jQuery Autocomplete was created by g3guy
Hi

I've faced with the typical problem of Province > Town dependency. The additional problem is that I'm currently using an Array dual scale that is using a filter array based on the previous response.

I'm working with numerous categories so have been trying to simplify as best possible.

While my Province dropdown is neat enough, my Town dropdown is rather large (since I've had to put in all possible towns).

Searching the forum posts I landed on the autocomplete workaround here:
manual.limesurvey.org/Workarounds:_Manip...wers_for_text_inputs

I figured this may be better to use. I tried it in Array (Text) but no luck there. Is it possible to use this autocomplete on arrays?

(even though I'm working with two different variables I'm happy for them to have the same options if it will make my Town variable easier to work with).

Thanks!
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 2 hours ago #106474 by DenisChenu
Replied by DenisChenu on topic jQuery Autocomplete
You can use autocomplete on array, just need the good id.

If you are in question text
$('#answer{SGQ}XCODE_Ycode').autocomplete(states, { if i don't make error.

You can have a look to at gitorious.org/ls-selectfilter

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The following user(s) said Thank You: tpartner, g3guy
The topic has been locked.
  • g3guy
  • g3guy's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
10 years 1 hour ago #106479 by g3guy
Replied by g3guy on topic jQuery Autocomplete
Thanks Denis for the reply. I must admit, I'm not quite sure how to incorporate your suggestion?

Current I have the following for my question text:
Code:
<script type="text/javascript" charset="utf-8">
        $(document).ready(function() {
                var qID = 32597;
                var states = "State1,State2".split(',');
                $('#question'+qID+' input.text').autocomplete({source: states});
                });
</script>Name your state:

Also, where would I use your ls-selectfilter?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 11 months ago #106485 by tpartner
Replied by tpartner on topic jQuery Autocomplete
Nice work Denis. We should add that to the workarounds.

Also, where would I use your ls-selectfilter?

You would place Denis' function in template.js or in the question source. Then you would apply the function to the question by placing this in the question source:
Code:
<script type="text/javascript" charset="utf-8">  
  $(document).ready(function() {
    selectFilterDualScale({QID});
  });
</script>

The answer codes for both scales must be the same length and the scale-2 options are filtered by the first n characters of the answer code, where n = (answer-code-length - 2). So, if you have 4-character answer codes, the filtering will be done by the first two characters. See screenshot below.

Attached is a working sample survey. In this survey I've also added a temporary fix for a bug in 2.05 that records data for unanswered dropdowns - bugs.limesurvey.org/view.php?id=8875 .

File Attachment:

File Name: limesurvey...1241.lss
File Size:25 KB



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: g3guy
The topic has been locked.
  • g3guy
  • g3guy's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
9 years 11 months ago #106486 by g3guy
Replied by g3guy on topic jQuery Autocomplete
Wow, that is a very elegant solution. I'm going to go with it on my survey and report anything picked up. This certainly does improve things substantially! :)
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 11 months ago - 9 years 11 months ago #106487 by tpartner
Replied by tpartner on topic jQuery Autocomplete
Yeah, note that when the bug is fixed you can remove this part from the script in the question source of the sample survey:

Code:
$('.array-flexible-duel-scale .dropdown-item select').each(function(i) {
  if($('option[selected="selected"]', this).length == 0) {
    $(this).prepend('<option value="">Please choose...</option>');
    $(this).val('');
  }
});

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 9 years 11 months ago by tpartner.
The topic has been locked.
  • g3guy
  • g3guy's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
9 years 11 months ago #106488 by g3guy
Replied by g3guy on topic jQuery Autocomplete
Yes, I did pick this part up from your example survey - thanks. Will keep an eye out on the updates.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 11 months ago #106493 by DenisChenu
Replied by DenisChenu on topic jQuery Autocomplete

tpartner wrote: Nice work Denis. We should add that to the workarounds.

Thanks Tony,

It's one of 'future' question attribute in plugin. But here there are a problem with first system if question is hidden at start... i think i fix it somewhere but don't remind where ...

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 11 months ago #106494 by tpartner
Replied by tpartner on topic jQuery Autocomplete

But here there are a problem with first system if question is hidden at start...

The only problem I can see is that the width of the cloned select is set to that of the original and if the row is hidden by filtering the original has no width.

Removing this line should do the trick:
Code:
$("#"+idNewSelectFilter).width($("#"+idSelectFilter).width());

Here's another survey with filtering applied to the array.

File Attachment:

File Name: limesurvey...ring.lss
File Size:27 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 11 months ago #106496 by DenisChenu
Replied by DenisChenu on topic jQuery Autocomplete
Yes, it's that, i think i fix it differently . And without this line the 'select' update his width (set to auto), i don't like it ;).

Denis

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
  • g3guy
  • g3guy's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
9 years 11 months ago #106580 by g3guy
Replied by g3guy on topic jQuery Autocomplete
Denis, Tony - thank you for all your help!

This section now works like a charm! (finally tested)

If I have any nit picks it would be that the options "jump" when selected. So as soon as I select my first option, both options shift to the right.
The topic has been locked.
More
9 years 11 months ago #107153 by lfanfoni
Replied by lfanfoni on topic jQuery Autocomplete
This script is a fantastic solution! Expecially for italians users...
In Italy we have 110 Province and 8.057 Comuni (cities).
I've adapted the script in order to have a unique ID for cities in each province (3 chars instead 2), beacause in many cases we have more than 100 cities for province.
In this example the lenght of answer code for both scales is fixed at 5 characters (maximum for anser code). First two characters is abbreviation of province (RM is Province of Rome). Lasts 3 characters is the unique ID for both scales, expecially for the Cities, so the maximum number of cities for province now is 999.
I've modified the scritp in the "Substring" arguments. For example:
Old: substring(0, $(this).val().length - 2)
New: substring(0, $(this).val().length - 3)
I attach a sample of this solution, with the modified script (I also commented).
I ask to Denis and Tony the permission to publish the complete solution with the modified script in the italian forum.
Thanks a lot for this discussion/solution.
Luciano

File Attachment:

File Name: dual_scale...char.lsq
File Size:22 KB

Se mi vuoi contattare, non mandare messaggi privati qui, bensì scrivi a lfanfoni at gmail.com
Per le livestream in italiano vai su: www.youtube.com/playlist?list=PLOSjjxAG9...SiiCsSz_JxIH7xJwLdPd
Le soluzioni LimeSurvey per l'Italia si trovano su: github.com/lfanfoni
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose