- Posts: 36
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Auto-suggest text field
- waitz
- Topic Author
- Offline
- Junior Member
Less
More
12 years 5 months ago #67872
by waitz
Version 2.73.1+171220
Auto-suggest text field was created by waitz
I have seen it somewhere in the forum, but I cannot find it.... :S
I had a script I could use in a sub-text field in a multiple short text question, that suggests answers based on what I start typing in the text field... The answers came from a list in the script of course.
I cannot find this back in the forum. Do you have an idea of a script like this?
I had a script I could use in a sub-text field in a multiple short text question, that suggests answers based on what I start typing in the text field... The answers came from a list in the script of course.
I cannot find this back in the forum. Do you have an idea of a script like this?
Version 2.73.1+171220
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10633
- Thank you received: 3697
12 years 5 months ago #67885
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Auto-suggest text field
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- Mazi
- Offline
- Official LimeSurvey Partner
12 years 5 months ago #67893
by Mazi
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
Replied by Mazi on topic Auto-suggest text field
Rajan, once you have added all these nice workarounds, can you create a copy of that survey so we can have a look at a life version?
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.
- waitz
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 36
- Thank you received: 0
12 years 5 months ago #67895
by waitz
Version 2.73.1+171220
Replied by waitz on topic Auto-suggest text field
Sure It is becoming quite advanced, nice for the user, and not so difficult to administer.
Version 2.73.1+171220
The topic has been locked.
- waitz
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 36
- Thank you received: 0
12 years 5 months ago #67901
by waitz
I tried to put it in the code of the main question and in the code of the subquestion. Where does it actually go, and why won't it work... :huh:
Version 2.73.1+171220
Replied by waitz on topic Auto-suggest text field
Hmmm... The text field I want to use this for is one of 5 subquestions in multiple short text.tpartner wrote: docs.limesurvey.org/Workarounds%3A+Manip...y#and_later_versions
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { var q1ID = #answer68164X61X1025FAM06; var states = "Alabama,Alaska,Arizona,Arkansas,California,Colorado,Connecticut,Delaware, District of Columbia,Florida,Georgia,Hawaii,Idaho,Illinois,Indiana,Iowa,Kansas,Kentucky, Louisiana,Maine,Montana,Nebraska,Nevada,New Hampshire,New Jersey,New Mexico,New York, North Carolina,North Dakota,Ohio,Oklahoma,Oregon,Maryland,Massachusetts,Michigan, Minnesota,Mississippi,Missouri,Pennsylvania,Rhode Island,South Carolina,South Dakota, Tennessee,Texas,Utah,Vermont,Virginia,Washington,West Virginia,Wisconsin,Wyoming".split(','); $('#question'+q1ID+' input.text').autocomplete({ source: states }); }); </script>
Version 2.73.1+171220
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10633
- Thank you received: 3697
12 years 5 months ago #67903
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Auto-suggest text field
You can place the script in the source of any question or subquestion. It just need to be present in the page.
To target a specific sub-question field, use something like this:
To target a specific sub-question field, use something like this:
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { var states = "Alabama,Alaska,Arizona,Arkansas,California,Colorado,Connecticut,Delaware, District of Columbia,Florida,Georgia,Hawaii,Idaho,Illinois,Indiana,Iowa,Kansas,Kentucky, Louisiana,Maine,Montana,Nebraska,Nevada,New Hampshire,New Jersey,New Mexico,New York, North Carolina,North Dakota,Ohio,Oklahoma,Oregon,Maryland,Massachusetts,Michigan, Minnesota,Mississippi,Missouri,Pennsylvania,Rhode Island,South Carolina,South Dakota, Tennessee,Texas,Utah,Vermont,Virginia,Washington,West Virginia,Wisconsin,Wyoming".split(','); $('#answer68164X61X1025FAM06').autocomplete({ source: states }); }); </script>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10633
- Thank you received: 3697
12 years 5 months ago #67905
by tpartner
Soon the survey will complete itself :laugh:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Auto-suggest text field
Sure It is becoming quite advanced, nice for the user, and not so difficult to administer.
Soon the survey will complete itself :laugh:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- waitz
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 36
- Thank you received: 0
12 years 5 months ago #67918
by waitz
Version 2.73.1+171220
Replied by waitz on topic Auto-suggest text field
Interesting thoughttpartner wrote: Soon the survey will complete itself :laugh:
Version 2.73.1+171220
The topic has been locked.
- waitz
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 36
- Thank you received: 0
12 years 4 months ago - 12 years 4 months ago #68106
by waitz
Version 2.73.1+171220
Replied by waitz on topic Auto-suggest text field
The script is working, but it is not mandatory that I choose one of the suggested words.
Is it possible to make this mandatory?
Is it possible to make this mandatory?
Version 2.73.1+171220
Last edit: 12 years 4 months ago by waitz.
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10633
- Thank you received: 3697
12 years 4 months ago #68112
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Auto-suggest text field
This code will apply the autocomplete plugin to an input and if a value is entered that is not in the data array an alert will be shown and the input will be set to null.
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { var states = "Alabama,Alaska,Arizona,Arkansas,California,Colorado,Connecticut,Delaware,District of Columbia,Florida,Georgia,Hawaii,Idaho,Illinois,Indiana,Iowa,Kansas,Kentucky,Louisiana,Maine,Montana,Nebraska,Nevada,New Hampshire,New Jersey,New Mexico,New York,North Carolina,North Dakota,Ohio,Oklahoma,Oregon,Maryland,Massachusetts,Michigan,Minnesota,Mississippi,Missouri,Pennsylvania,Rhode Island,South Carolina,South Dakota,Tennessee,Texas,Utah,Vermont,Virginia,Washington,West Virginia,Wisconsin,Wyoming".split(','); var msg = 'You must select a value from the list.'; mandatoryAutocomplete('#answer68164X61X1025FAM06', states); function mandatoryAutocomplete(inputID, data) { $(inputID).autocomplete({ source: data }); $(inputID).change(function(){ //$('#answer68164X61X1025FAM06').change(function(){ var okay = 0; $(states).each(function(){ if($(inputID).val() == this) { okay = 1; } }); if(okay < 1) { alert (msg); $(inputID).val(''); } }); } }); </script>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- waitz
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 36
- Thank you received: 0
12 years 4 months ago #68123
by waitz
Version 2.73.1+171220
Replied by waitz on topic Auto-suggest text field
Hmmm, it wont really work, not even the auto-suggestion. I see that it says inputID, data and source:data while the original said states. I tried to change them to states instead of data, and then the auto-suggestion works again, but not that it is mandatory to choose from one of the items in the list...
Version 2.73.1+171220
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10633
- Thank you received: 3697
12 years 4 months ago - 12 years 4 months ago #68127
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Auto-suggest text field
You should not need to change those. They are defined parameters of the function.
Here is a refined version that opens the selection list when the input is focused. The only thing you should need to modify is "answer68164X61X1025FAM06" for different input IDs.
Here is a refined version that opens the selection list when the input is focused. The only thing you should need to modify is "answer68164X61X1025FAM06" for different input IDs.
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { var states = "Alabama,Alaska,Arizona,Arkansas,California,Colorado,Connecticut,Delaware,District of Columbia,Florida,Georgia,Hawaii,Idaho,Illinois,Indiana,Iowa,Kansas,Kentucky,Louisiana,Maine,Montana,Nebraska,Nevada,New Hampshire,New Jersey,New Mexico,New York,North Carolina,North Dakota,Ohio,Oklahoma,Oregon,Maryland,Massachusetts,Michigan,Minnesota,Mississippi,Missouri,Pennsylvania,Rhode Island,South Carolina,South Dakota,Tennessee,Texas,Utah,Vermont,Virginia,Washington,West Virginia,Wisconsin,Wyoming".split(','); var msg = 'You must select a value from the list.'; mandatoryAutocomplete('#answer68164X61X1025FAM06', states); function mandatoryAutocomplete(inputID, data) { $(inputID).autocomplete({ source: data, minLength: 0, change: function(event, ui) { var okay = 0; if($(inputID).val() != '') { $(data).each(function(){ if($(inputID).val() == this) { okay = 1; } }); } if(okay < 1) { alert (msg); $(inputID).val(''); } } }).focus(function(){ if (this.value == "") { $(this).autocomplete('search', ''); } }); } }); </script>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 12 years 4 months ago by tpartner.
The topic has been locked.