<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>select2 Archives - scmGalaxy</title>
	<atom:link href="https://www.scmgalaxy.com/tutorials/tag/select2/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.scmgalaxy.com/tutorials/tag/select2/</link>
	<description>A Platform for Software Engineers</description>
	<lastBuildDate>Sat, 14 Aug 2021 06:49:49 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1</generator>
	<item>
		<title>How to add placeholder to select2.js</title>
		<link>https://www.scmgalaxy.com/tutorials/how-to-add-placeholder-to-select2-js/</link>
					<comments>https://www.scmgalaxy.com/tutorials/how-to-add-placeholder-to-select2-js/#respond</comments>
		
		<dc:creator><![CDATA[Amardeep Dubey]]></dc:creator>
		<pubDate>Sat, 14 Aug 2021 06:49:46 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[select2]]></category>
		<guid isPermaLink="false">https://www.scmgalaxy.com/tutorials/?p=7935</guid>

					<description><![CDATA[<p>Single select placeholders Multi-select placeholders Using placeholders with AJAX Select2 supports placeholders for all configurations, including AJAX. You will still [&#8230;]</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/how-to-add-placeholder-to-select2-js/">How to add placeholder to select2.js</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">Single select placeholders</h2>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="829" height="162" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/image-95.png" alt="" class="wp-image-7936" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/image-95.png 829w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/image-95-300x59.png 300w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/image-95-768x150.png 768w" sizes="(max-width: 829px) 100vw, 829px" /></figure>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
&amp;lt;select class=&quot;js-example-placeholder-single js-states form-control&quot;&gt;
  &amp;lt;option&gt;&amp;lt;/option&gt;
&amp;lt;/select&gt;

</pre></div>

<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
$(&quot;.js-example-placeholder-single&quot;).select2({
    placeholder: &quot;Select a state&quot;,
    allowClear: true
});
</pre></div>


<h2 class="wp-block-heading">Multi-select placeholders</h2>



<figure class="wp-block-image size-full"><img decoding="async" width="868" height="112" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/image-96.png" alt="" class="wp-image-7937" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/image-96.png 868w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/image-96-300x39.png 300w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/image-96-768x99.png 768w" sizes="(max-width: 868px) 100vw, 868px" /></figure>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
&amp;lt;select class=&quot;js-example-placeholder-multiple js-states form-control&quot; multiple=&quot;multiple&quot;&gt;&amp;lt;/select&gt;
</pre></div>

<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
$(&quot;.js-example-placeholder-multiple&quot;).select2({
    placeholder: &quot;Select a state&quot;
});
</pre></div>


<h2 class="wp-block-heading">Using placeholders with AJAX</h2>



<p class="wp-block-paragraph">Select2 supports placeholders for all configurations, including AJAX. You will still need to add in the empty <code>&lt;option></code> if you are using a single select.</p>



<p class="wp-block-paragraph">When using Select2 <strong>in single-selection mode</strong>, the placeholder option will be passed through the <code>templateSelection</code> callback if specified. You can use some additional logic in this callback to check the <code>id</code> property and apply an alternative transformation to your placeholder option:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
$(&#039;select&#039;).select2({
  templateSelection: function (data) {
    if (data.id === &#039;&#039;) { // adjust for custom placeholder values
      return &#039;Custom styled placeholder text&#039;;
    }

    return data.text;
  }
});
</pre></div><p>The post <a href="https://www.scmgalaxy.com/tutorials/how-to-add-placeholder-to-select2-js/">How to add placeholder to select2.js</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.scmgalaxy.com/tutorials/how-to-add-placeholder-to-select2-js/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
