Check out the LimeSurvey source code on GitHub!

jQuery Autocomplete

More
2 years 10 months ago #106446 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!

Please Log in to join the conversation.

More
2 years 10 months ago #106474 by DenisChenu
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 (or search sondages pro).
The following user(s) said Thank You: tpartner, g3guy

Please Log in to join the conversation.

More
2 years 10 months ago #106479 by g3guy
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:
<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?

Please Log in to join the conversation.

More
2 years 10 months ago #106485 by tpartner
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:
<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.
Attachments:
The following user(s) said Thank You: g3guy

Please Log in to join the conversation.

More
2 years 10 months ago #106486 by g3guy
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! :)

Please Log in to join the conversation.

More
2 years 10 months ago - 2 years 10 months ago #106487 by tpartner
Yeah, note that when the bug is fixed you can remove this part from the script in the question source of the sample survey:

$('.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: 2 years 10 months ago by tpartner.

Please Log in to join the conversation.

More
2 years 10 months ago #106488 by g3guy
Yes, I did pick this part up from your example survey - thanks. Will keep an eye out on the updates.

Please Log in to join the conversation.

More
2 years 10 months ago #106493 by DenisChenu

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 (or search sondages pro).

Please Log in to join the conversation.

More
2 years 10 months ago #106494 by tpartner

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:
$("#"+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.
Attachments:

Please Log in to join the conversation.

More
2 years 10 months ago #106496 by DenisChenu
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 (or search sondages pro).

Please Log in to join the conversation.

More
2 years 10 months ago #106580 by g3guy
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.

Please Log in to join the conversation.

More
2 years 9 months ago #107153 by lfanfoni
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
Attachments:

Please Log in to join the conversation.

More
2 years 9 months ago - 2 years 9 months ago #107158 by DenisChenu
The script don't have actually a licence ?

MIT surely.... (then yes ... you can copy /paste / adapt / etc ...

And yes : MIT at starting : gitorious.org/ls-selectfilter/ls-selectf...d:selectfilter.js#L3

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
Last Edit: 2 years 9 months ago by DenisChenu.
The following user(s) said Thank You: lfanfoni

Please Log in to join the conversation.

More
2 years 9 months ago #107162 by lfanfoni
I've added a comment to documentate my modify. This:
/*
Modified Version by Luciano Fanfoni 04/04/2014
Fixed Lenght of both Answer Code (scale 1 & 2): 5
Firsts 2 chars used to filter. Lasts 3 chars used to identify unically options of scale2
Example of Modified code:
Old: substring(0, $(this).val().length - 2)
New: substring(0, $(this).val().length - 3)


Distributed under MIT licence
*/

Please Log in to join the conversation.

More
1 year 8 months ago #120697 by mascarpone
Hi Guys,

Back on this thread which I struggle a bit to understand. I have 2 questions here:

1. is there somewhere a summary of how this can be tackled (Denis maybe)? as there seem to be different versions, with bug fixes, etc. Any sort of a "final word" on this?

2. anything "more robust" planned along those lines in future releases?

Cheers!

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form