1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <section>
- <h2 id="allowClear">
- Can I allow users to clear their selections?
- </h2>
- <p>
- You can allow people to clear their current selections with the <code>allowClear</code> option when initializing Select2. Setting this option to <code>true</code> will enable an "x" icon that will reset the selection to the placeholder.
- </p>
- {% highlight js linenos %}
- $('select').select2({
- placeholder: 'This is my placeholder',
- allowClear: true
- });
- {% endhighlight %}
- <h3>
- Why is a placeholder required?
- </h3>
- {% include options/not-written.html %}
- <h3>
- The "x" icon is not clearing the selection
- </h3>
- {% include options/not-written.html %}
- <h3>
- Can users remove all of their selections in a multiple select at once?
- </h3>
- <p>
- Yes, by setting the value of the control to <code>null</code>:
- </p>
- {% highlight js linenos %}
- $('select').val(null).trigger('change');
- {% endhighlight %}
- <p>
- See <a href="examples.html#programmatic">https://select2.github.io/examples.html#programmatic</a> for a working example.
- </p>
- </section>
|