Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:
  • Page:
  • 1
  • 2

TOPIC: jQuery Autocomplete

jQuery Autocomplete 2 years 4 months ago #106446

  • g3guy
  • g3guy's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 19
  • Thank you received: 1
  • Karma: 0
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 administrator has disabled public write access.

jQuery Autocomplete 2 years 4 months ago #106474

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9254
  • Thank you received: 1319
  • Karma: 382
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 developpement are on my free time (Say thanks ?).
A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous
The administrator has disabled public write access.
The following user(s) said Thank You: tpartner, g3guy

jQuery Autocomplete 2 years 4 months ago #106479

  • g3guy
  • g3guy's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 19
  • Thank you received: 1
  • Karma: 0
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?
The administrator has disabled public write access.

jQuery Autocomplete 2 years 4 months ago #106485

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6114
  • Thank you received: 1356
  • Karma: 532
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.
The administrator has disabled public write access.
The following user(s) said Thank You: g3guy

jQuery Autocomplete 2 years 4 months ago #106486

  • g3guy
  • g3guy's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 19
  • Thank you received: 1
  • Karma: 0
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 administrator has disabled public write access.

jQuery Autocomplete 2 years 4 months ago #106487

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6114
  • Thank you received: 1356
  • Karma: 532
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 4 months ago by tpartner.
The administrator has disabled public write access.

jQuery Autocomplete 2 years 4 months ago #106488

  • g3guy
  • g3guy's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 19
  • Thank you received: 1
  • Karma: 0
Yes, I did pick this part up from your example survey - thanks. Will keep an eye out on the updates.
The administrator has disabled public write access.

jQuery Autocomplete 2 years 4 months ago #106493

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9254
  • Thank you received: 1319
  • Karma: 382
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 developpement are on my free time (Say thanks ?).
A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous
The administrator has disabled public write access.

jQuery Autocomplete 2 years 4 months ago #106494

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6114
  • Thank you received: 1356
  • Karma: 532
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.
The administrator has disabled public write access.

jQuery Autocomplete 2 years 4 months ago #106496

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9254
  • Thank you received: 1319
  • Karma: 382
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 developpement are on my free time (Say thanks ?).
A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous
The administrator has disabled public write access.

jQuery Autocomplete 2 years 4 months ago #106580

  • g3guy
  • g3guy's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 19
  • Thank you received: 1
  • Karma: 0
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 administrator has disabled public write access.

jQuery Autocomplete 2 years 3 months ago #107153

  • lfanfoni
  • lfanfoni's Avatar
  • Offline
  • Platinum Lime
  • Posts: 536
  • Thank you received: 98
  • Karma: 24
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
The administrator has disabled public write access.

jQuery Autocomplete 2 years 3 months ago #107158

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9254
  • Thank you received: 1319
  • Karma: 382
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 developpement are on my free time (Say thanks ?).
A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous
Last Edit: 2 years 3 months ago by DenisChenu.
The administrator has disabled public write access.
The following user(s) said Thank You: lfanfoni

jQuery Autocomplete 2 years 3 months ago #107162

  • lfanfoni
  • lfanfoni's Avatar
  • Offline
  • Platinum Lime
  • Posts: 536
  • Thank you received: 98
  • Karma: 24
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
*/
The administrator has disabled public write access.

jQuery Autocomplete 1 year 2 months ago #120697

  • mas_carpone
  • mas_carpone's Avatar
  • Offline
  • Gold Lime
  • Posts: 187
  • Thank you received: 14
  • Karma: 3
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!
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 1.066 seconds
Imprint                   Data Protection Statement                  Revocation information and revocation form