select2 autotagging with multi-value select boxes

Plus d'informations
il y a 1 mois 5 jours #181953 par socius
COM_KUNENA_MESSAGE_CREATED_NEW
Hi everybody,

I try to make use of the select2-jquery Plugin ( select2.org/ ) to create dropdown-choices with some nice features (search, autocomplete, multiple selection, autotagging). That works by creating text inputs (e.g. (multiple) short texts, or text arrays) and adding the script to the question, similar to manual.limesurvey.org/Workarounds:_Manip...wers_for_text_inputs . select2 dropdowns look especially good on mobile devices (imho better than standard drop down selections which fill up the screen) and I think these features of select2 would be great to have. I saw that select2 was mentioned here before ( www.limesurvey.org/community/forums/deve...th-search-box#155643 ) and I just noticed that @DenisChenu has a Plugin using select2 www.limesurvey.org/community/forums/desi...each-question#160518 ).

I implemented select2 just like in the autocomplete example mentioned above. The standard dropdowns work fine, also the multiple choice (s. below). (Remark: select2 css has to be copied to template.css)

</script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.5/js/select2.full.js"></script>
<script type="text/javascript" charset="utf-8"> 
$(document).ready(function(){ 
var qID = {QID};  /* identify question */  
var wordList1=[ { id: 1, text: 'Option 1' }, { id: 2, text: 'Option 2' }, { id: 3, text: 'Option 3' }, { id: 4, text: 'Option 4' } ];  
$('#question'+qID+' input[type="text"][id$="_1"]').select2({ data: wordList1, width: '95%', placeholder: '...', tags: true, multiple: true, tokenSeparators: [',', ' '] } ); } );
</script>





But: the feature I want to use (with the code above) is autotagging with multi-value select boxes (s. select2.org/tagging ). That should actually be easy to achieve (according to the documentation and all the fiddles that show how e.g. jsfiddle.net/alanng/zg1paLsj/ ) but I just can't get this right.

When I enter a new answer (that is not among the given options) I'd expect that this answer stays as an answer just like the others - but I get the message "No results found" (which would be correct with default options (without "tags: true"), since this answer is not in the list), but I think with "tags: true" this should work - (it does not ;-)



Does anybody of you have experiences how to do this? I use Limesurvey 2.6.7 LTS with Denis' SkeletonQuest - Template.


Thanks for any hint and for your time!
Best, G
Pièces jointes :

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 1 mois 4 jours - il y a 1 mois 4 jours #182004 par socius
COM_KUNENA_MESSAGE_REPLIED_NEW
Hi,
I just noticed that the code I posted contains a small error (merely a copy/paste/edit error and not the reason for the mentioned problem with select2)

The code started with "</script ... " which is a bad start for a script ;-) Please replace it with "<script ..."
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.5/js/select2.full.js"></script>
<script type="text/javascript" charset="utf-8"> 
$(document).ready(function(){ 
var qID = {QID};  /* identify question */  
var wordList1=[ { id: 1, text: 'Option 1' }, { id: 2, text: 'Option 2' }, { id: 3, text: 'Option 3' }, { id: 4, text: 'Option 4' } ];  
$('#question'+qID+' input[type="text"][id$="_1"]').select2({ data: wordList1, width: '95%', placeholder: '...', tags: true, multiple: true, tokenSeparators: [',', ' '] } ); } );
</script>

Best, G
Last edit: il y a 1 mois 4 jours by socius. Raison: Less smileys :-)
Les utilisateur(s) suivant ont remercié: cdorin

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 1 mois 4 jours #182006 par tpartner
COM_KUNENA_MESSAGE_REPLIED_NEW
Can you attach a small sample survey (.lss file)?

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Les utilisateur(s) suivant ont remercié: socius

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 1 mois 4 jours #182012 par socius
COM_KUNENA_MESSAGE_REPLIED_NEW
Hi!

thanks for your response @tpartner - sorry it took me some time to put this .lss together. It comes with an adapted default template (for 2.6.7 LTS) that contains the select2 css from cdnjs.cloudflare.com/ajax/libs/select2/4.0.5/css/select2.css .
The select2 fields link to cdnjs.cloudflare.com/ajax/libs/select2/4.0.5/js/select2.full.js

I continued playing around to get the autotagging with multi-value select boxes (s. select2.org/tagging ) running, but had no success. In the last example (the .lss contains 4 examples - the first 3 working) select 2 should save the input as a tag - but it does not (it seems that it's not as simple as in the documentation - or maybe it is just me ;-) )

Thanks a lot for any help on this!
Best, G
Pièces jointes :

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 1 mois 4 jours #182059 par tpartner
COM_KUNENA_MESSAGE_REPLIED_NEW
I don't think tagging is supported with text inputs - github.com/select2/select2/issues/3022

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

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 1 mois 4 jours #182066 par socius
COM_KUNENA_MESSAGE_REPLIED_NEW
Hi,

thanks a lot @tpartner for that link! I saw this a number of times but did not know where to put this. I also found this here "No more hidden input tags" ( select2.org/upgrading/migrating-from-35 ).

But: at the link you sent, it seems that there is a workaround github.com/select2/select2/issues/3022#issuecomment-316022305 . I just naively put it into the question text and did as it's done in this fiddle: jsfiddle.net/lingceng/h5baz3bo/13/

and it partly works! (s. below)





Wow. It seems that the workaround only makes the last field a select2 field - but that's better than nothing! Who can make this work? I have no idea how far it is from here ;-)

This is the question text / script I used (I attached the updated .lss)
 
<p>Example 3v3: Question?</p>
<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 qID = {QID};  /* identify question */  
var wordList1=[ { id: 1, text: 'Option 1' }, { id: 2, text: 'Option 2' }, { id: 3, text: 'Option 3' }, { id: 4, text: 'Option 4' } ];  select2InputTags($('#question'+qID+' input[type="text"][id$="_1"]')).select2({ data: wordList1, width: '95%', minimumResultsForSearch: -1, tags: true, placeholder: "...", multiple: true }); 
});
</script>
 


Thanks for your time and help!
G
Pièces jointes :

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 1 mois 3 jours #182068 par tpartner
COM_KUNENA_MESSAGE_REPLIED_NEW
Try this:

<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 qID = {QID};  /* identify question */  
		var wordList1=[ { id: 1, text: 'Option 1' }, { id: 2, text: 'Option 2' }, { id: 3, text: 'Option 3' }, { id: 4, text: 'Option 4' } ];
 
		$('#question'+qID+' input[type="text"][id$="_1"]').each(function(i) {
 
			select2InputTags($(this)).select2({ 
				data: wordList1, width: '95%', 
				minimumResultsForSearch: -1, 
				tags: true, placeholder: "...", 
				multiple: true 
			}); 
		});
	});
</script>



Sample survey attached:

Fichier attaché :

Nom du fichier : limesurvey...3662.lss
Taille du ficher :19 ko

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Pièces jointes :
Les utilisateur(s) suivant ont remercié: socius

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 1 mois 3 jours #182069 par socius
COM_KUNENA_MESSAGE_REPLIED_NEW
Thanks so much @tpartner! That's absolutely perfect!

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 1 mois 3 jours #182086 par socius
COM_KUNENA_MESSAGE_REPLIED_NEW
Hi again,

thanks again @tpartner - select2 now works! Really makes it easy to create/combine multiple choice + open questions.

I just noticed that the only thing that does not work completey work is going back and forth in the survey (s. attached survey). I did some checks and it's not select2() that's causing this, but the helpful workaround select2InputTags() (s. github.com/select2/select2/issues/3022#issuecomment-316022305 )

I wrote a comment on the github page wher the author posted this - some parts of it here to illustrate the issue. I don't know how hard it is to solve this.

I just noticed some troubles with reloading fields with select2InputTags(). I work with a webquestionnaire tool (limesurvey) and use select2 4.0.5 to augment the textfields with multiselect and tagging. I just noticed, that when I fill in a field (select2 with select2InputTags), change page (one question per page) and come back the values (saved in the text fields) are reloaded, but it shows only the id, not the text.

La pièce jointe est absente ou indisponible



after forth and back the text is gone (also from the options in the drop down) (the ids are still here):

La pièce jointe est absente ou indisponible



So if I have 4 Options and loading them from an array: [...]

1) I choose Option 1, Option 2 and type some text 'asdfg'.
2) I go forth to the next page and come back
3a) the preloaded content for the text field is '1','2','asdfg' - so it only shows the ids, not the text.
3b) the dropdown text for options '1' and '2' is also replaced by the id, e.g. there is no 'Option 1' in the dropdown, but only '1' . (In this case it's '1', '2', 'asdfg', 'Option 3', 'Option 4')

If anybody knows how to adapt the gist (s. github link) that would be great. If I get an answer from the author I'll immediately post it here, but maybe someone here is quicker - let's see :-)

Thanks for your time!
Best, G

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 1 mois 3 jours #182087 par socius
COM_KUNENA_MESSAGE_REPLIED_NEW
Hi,

sorry the files got lost when I posted this. Here they come (2 screenshots and a .lss)



after forth and back:



Best, G
Pièces jointes :

Connexion ou Créer un compte pour participer à la conversation.

Commencez dès maintenant !

Créez simplement un compte et commencez à utiliser LimeSurvey dès aujourd'hui.

Inscrivez-vous maintenant

Inscrivez-vous à notre Newsletter!