1
0
mirror of synced 2025-02-09 16:49:24 +03:00

Answer question about using HTML in selection template

This closes https://github.com/select2/select2/pull/4606.
This commit is contained in:
Stephen A. Wilson 2016-09-22 11:40:43 -04:00 committed by Kevin Brown
parent 625fc78ee6
commit 0a67287c7a

View File

@ -27,11 +27,24 @@ $('select').select2({
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>