custom-widgets
custom-widgets copied to clipboard
select2 tags option
I am doing an heavy use of select2/slect2tagbox widgets in my survey. I slightly modify them in order to exploit the tags option of select2 plugin which let add new select options on the fly. To enable the tags feature I had to add a new property tags to the question definition. It works but that option does conceptually what hasOther option does in surveyjs world.
So I would enable the tags option simply by checking the hasOther property value instead of create a brand new property but problems raised as hasOther implies other UX consequences which select2 plugin already implements
Is there any easy way to merge select2 tags option and surveyjs hasOther property?
@masciugo hello! I think that we don't need include this override of hasOther
to our widget. Because diffrent users can have various use cases. In your example I think that the easiest way to do it is using filter
:
question.visibleChoices.filter(function(choice) {
return choice.value !== "other"
}).map(function(choice) {
return {
id: choice.value,
text: choice.text
};
})
and the updated plunk: https://plnkr.co/edit/w2QJrnDvgH0RuAVRYFJ7?p=preview
Is it ok for you?
thanks @dmitrykurmanov but maybe I was not clear. I would like a a widget where setting hasOther property enable the select2 tags option. In the last question you add hasOther property while keeping tags property which actually enable the creation feature. Moreover your plunker does not work as expected: the first time you create an option it does not appear.
I just wonder if there is a way to avoid using my brand new tags property to enable option creation: instead using the hasOther property
However I used your suggestion in a simplified version of my example (only select2 dropdown) which works but not in the matrixdynamic. https://plnkr.co/edit/4ABtQbWWSRLhJh3PEpqy?p=preview
can you have a look? then I will try to add that functionality to the other widget
thanks!
@dmitrykurmanov Let's implement this functionality out of the box.
Thank you, Andrew