Skip to content

Commit

Permalink
Answer question about using HTML in selection template
Browse files Browse the repository at this point in the history
This closes select2#4606.
  • Loading branch information
Zeragamba authored and kevin-brown committed Dec 30, 2016
1 parent 625fc78 commit 0a67287
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions docs/_includes/options/selections/templating.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,24 @@ <h3>
I am using HTML in my selection template but it isn't displaying it
</h3>

{% include options/not-written.html %}
<p>
If you want to use HTML in your selection template, you will need to return a jQuery object. Otherwise, Select2 will assume that your template only returns text and will escape it.
</p>

{% highlight js linenos %}
function template(data, container) {
return $('<strong></strong>')
.text(data.text);
}

$('select').select2({
templateSelection: template
});
{% endhighlight %}

<h3>
How can I access the container where the selection is displayed?
</h3>

{% include options/not-written.html %}
</section>
</section>

0 comments on commit 0a67287

Please sign in to comment.