1
0
mirror of synced 2024-11-30 08:36:03 +03:00
select2/pages/01.getting-started/02.basic-usage/docs.md
2017-09-02 20:34:47 -04:00

2.4 KiB

title taxonomy process never_cache_twig
Basic Usage
category
docs
twig
true
true

Single select boxes

Select2 was designed to be a replacement for the standard <select> box that is displayed by the browser. By default it supports all options and operations that are available in a standard select box, but with added flexibility.

Select2 can take a regular select box like this...

and turn it into this...

<select class="js-example-basic-single">
  <option value="AL">Alabama</option>
    ...
  <option value="WY">Wyoming</option>
</select>

Select2 will register itself as a jQuery function if you use any of the distribution builds, so you can call .select2() on any jQuery selector where you would like to initialize Select2.

$('.js-example-basic-single').select2();

Multi-select boxes (pillbox)

Select2 also supports multi-value select boxes. The select below is declared with the multiple attribute.

<script type="text/javascript">
$(".js-example-basic-multiple").select2();
</script>

<select class="js-example-basic-multiple" multiple="multiple">
  <option value="AL">Alabama</option>
    ...
  <option value="WY">Wyoming</option>
</select>