- Posts: 166
- Thank you received: 26
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
select2 autotagging with multi-value select boxes
- davebostockgmail
- Offline
- Elite Member
Less
More
4 years 11 months ago #184504
by davebostockgmail
Replied by davebostockgmail on topic select2 autotagging with multi-value select boxes
Here is the attached example lss file
I realised that I needed to include the CSS for the styling .. .my bad
Now all I need to understand is how a survey taker can add items not in the dropdown ... I have looked at the tags: tags but that doesn't seem to work?
Thanks
Dave
I realised that I needed to include the CSS for the styling .. .my bad
Now all I need to understand is how a survey taker can add items not in the dropdown ... I have looked at the tags: tags but that doesn't seem to work?
Thanks
Dave
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
4 years 11 months ago #184509
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 select2 autotagging with multi-value select boxes
The problem is that you did not implement the select2InputTags() function.
Notes:
- You need to click ENTER to accept the custom input.
- If a select2 item is selected, the associated id is stored in the data, not the label.
- As far as I know, the bug reported above about returning to the page is not addressed.
Sample survey attached:
Notes:
- You need to click ENTER to accept the custom input.
- If a select2 item is selected, the associated id is stored in the data, not the label.
- As far as I know, the bug reported above about returning to the page is not addressed.
Code:
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.7/css/select2.min.css" rel="stylesheet" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.5/js/select2.full.js"></script> <script src="https://rawgit.com/lingceng/d1cd5ca5db9a777b31487769242c422f/raw/69e98eeb1a154d625bb85e3420b7738f5f56961c/select2_input_tags.js"></script> <script type="text/javascript" charset="utf-8"> $(document).ready(function(){ var data=[ { id: 1, text: 'Option 1' }, { id: 2, text: 'Option 2' }, { id: 3, text: 'Option 3' }, { id: 4, text: 'Option 4' } ]; select2InputTags($('#question{QID} input:text')).select2({ data: data, width: '95%', minimumResultsForSearch: -1, tags: true, tokenSeparators: [',', ' '], placeholder: "...", multiple: true }); }); </script>
Sample survey attached:
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: DenisChenu, davebostockgmail
The topic has been locked.
- davebostockgmail
- Offline
- Elite Member
Less
More
- Posts: 166
- Thank you received: 26
4 years 11 months ago - 4 years 11 months ago #184512
by davebostockgmail
Replied by davebostockgmail on topic select2 autotagging with multi-value select boxes
Thank you so much ... It was really starting to bug me.
I have made a couple of adjustments in case anyone else is looking for something like this
The first is to add to the script to press Enter on page load so the question is ready for the participant and the second is to remove the ' ' from the token separator as what we are collecting is hobbies so with it in there - "Stamp collecting" became "Stamp" and "collecting" outside of that this works perfectly.
Thanks again
Dave
Updated Code
<link href=" cdnjs.cloudflare.com/ajax/libs/select2/4.../css/select2.min.css " rel="stylesheet" />
<script src=" cdnjs.cloudflare.com/ajax/libs/select2/4.0.5/js/select2.full.js ">
<script src=" rawgit.com/lingceng/d1cd5ca5db9a777b3148...elect2_input_tags.js ">
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
var e = jQuery.Event( "keydown", { keyCode: 13 } );
$("body").trigger(e);
var data=[ { id: 1, text: 'Option 1' }, { id: 2, text: 'Option 2' }, { id: 3, text: 'Option 3' }, { id: 4, text: 'Option 4' } ];
select2InputTags($('#question{QID} input:text')).select2({
data: data,
width: '95%',
minimumResultsForSearch: -1,
tags: true,
tokenSeparators: ,
placeholder: "...",
multiple: true
});
});
</script>
I have made a couple of adjustments in case anyone else is looking for something like this
The first is to add to the script to press Enter on page load so the question is ready for the participant and the second is to remove the ' ' from the token separator as what we are collecting is hobbies so with it in there - "Stamp collecting" became "Stamp" and "collecting" outside of that this works perfectly.
Thanks again
Dave
Updated Code
<link href=" cdnjs.cloudflare.com/ajax/libs/select2/4.../css/select2.min.css " rel="stylesheet" />
<script src=" cdnjs.cloudflare.com/ajax/libs/select2/4.0.5/js/select2.full.js ">
<script src=" rawgit.com/lingceng/d1cd5ca5db9a777b3148...elect2_input_tags.js ">
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
var e = jQuery.Event( "keydown", { keyCode: 13 } );
$("body").trigger(e);
var data=[ { id: 1, text: 'Option 1' }, { id: 2, text: 'Option 2' }, { id: 3, text: 'Option 3' }, { id: 4, text: 'Option 4' } ];
select2InputTags($('#question{QID} input:text')).select2({
data: data,
width: '95%',
minimumResultsForSearch: -1,
tags: true,
tokenSeparators: ,
placeholder: "...",
multiple: true
});
});
</script>
Last edit: 4 years 11 months ago by davebostockgmail.
The topic has been locked.