Add text when adding not existing tags

Hi

Is it possible to add some text when user write a non-exist tag ?

For exemple, in my options have got :

  • A
  • B
  • C

If my user write D, is it possible to havd “Adding item D” not only “D” ?

Thanks!

I know the templating feature will do it for a single-select Select2. If you’re using a multiple select, I’m not sure whether the templating callback applies to the 'tags" it displays, but it’s worth a try.

In your templating callback function you can distinguish an item that the user created from one that’s “native” to the select by looking for the attribute “data-select2-tag” on the HTML option element that is contained in the object passed to the callback. (The passed in object has an “element” property that points to the HTML option element. You can examine this property to retrieve its “data-select2-tag” attribute. See the sample code at the link I posted above.)