Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: jQuery Autocomplete

jQuery Autocomplete 4 months 1 week ago #106446

  • g3guy
  • g3guy's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 14
  • 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 4 months 1 week ago #106474

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6238
  • Thank you received: 794
  • Karma: 238
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
The administrator has disabled public write access.
The following user(s) said Thank You: tpartner, g3guy

jQuery Autocomplete 4 months 1 week ago #106479

  • g3guy
  • g3guy's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 14
  • 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 4 months 1 week ago #106485

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4071
  • Thank you received: 748
  • Karma: 341
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_survey_8831241.lss
File Size: 25 KB


Capture_2014-03-19.png
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
The following user(s) said Thank You: g3guy

jQuery Autocomplete 4 months 1 week ago #106486

  • g3guy
  • g3guy's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 14
  • 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 4 months 1 week ago #106487

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4071
  • Thank you received: 748
  • Karma: 341
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 4 months 1 week ago by tpartner.
The administrator has disabled public write access.

jQuery Autocomplete 4 months 1 week ago #106488

  • g3guy
  • g3guy's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 14
  • 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 4 months 1 week ago #106493

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6238
  • Thank you received: 794
  • Karma: 238
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 ...
The administrator has disabled public write access.

jQuery Autocomplete 4 months 1 week ago #106494

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4071
  • Thank you received: 748
  • Karma: 341
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_survey_883124_with_filtering.lss
File Size: 27 KB
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

jQuery Autocomplete 4 months 1 week ago #106496

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6238
  • Thank you received: 794
  • Karma: 238
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
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.186 seconds
Donation Image