templating.html 942 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <section>
  2. <h2 id="templateSelection">
  3. How can I customize the way selections are displayed?
  4. </h2>
  5. <p>
  6. When a selection is made by the user Select2 will display the text of the option by default, just like how it is displayed in a standard select box. You can override the display of the selection by setting the <code>templateSelection</code> option to a JavaScript function.
  7. </p>
  8. {% highlight js linenos %}
  9. function template(data, container) {
  10. return data.text;
  11. }
  12. $('select').select2({
  13. templateSelection: template
  14. });
  15. {% endhighlight %}
  16. <h3>
  17. Nothing is being displayed when I select an option
  18. </h3>
  19. {% include options/not-written.html %}
  20. <h3>
  21. I am using HTML in my selection template but it isn't displaying it
  22. </h3>
  23. {% include options/not-written.html %}
  24. <h3>
  25. How can I access the container where the selection is displayed?
  26. </h3>
  27. {% include options/not-written.html %}
  28. </section>