# Chosen

Chosen is a JavaScript plugin for jQuery and Prototype that makes long, unwieldy select boxes much more user-friendly. For more information (including usage, explanation and faqs), check out the online documentation.

## Multiple Select

Turns This
Into This

## <optgroup> Support

Single Select with Groups
Multiple Select with Groups

## Selected and Disabled Support

Chosen automatically highlights selected options and removes disabled options.

Single Select
Multiple Select

## Default Text Support

Chosen automatically sets the default field text ("Choose a country...") by reading the select element's data-placeholder value. If no data-placeholder value is present, it will default to "Select Some Option" or "Select Some Options" depending on whether the select is single or multiple. You can change these elements in the plugin js file as you see fit.

`<select data-placeholder="Choose a country..." style="width:350px;" multiple class="chzn-select">`

Note: on single selects, the first element is assumed to be selected by the browser. To take advantage of the default text support, you will need to include a blank option as the first element of your select list.

## No Results Text Support

Setting the "No results" search text is as easy as passing an option when you create Chosen:

`New Chosen($("chzn_select_field"),{no_results_text: "No results matched"});`

## Allow Deselect on Single Selects

When a single select box isn't a required field, you can set `allow_single_deselect: true` and Chosen will add a UI element for option deselection. This will only work if the first option has blank text.

## Right to Left Support

Chosen supports right to left select boxes too. just add `"chzn-rtl"` in addition to `"chzn-select"` to your select tags and you are good to go.

`<select class="chzn-select chzn-rtl">`

Single right to left select
Multiple right to left select

## Change / Update Events

- ### Form Field Change

  When working with form fields, you often want to perform some behavior after a value has been selected or deselected. Whenever a user selects a field in Chosen, it triggers a "change" event* on the original form field. That let's you do something like this:

  `$("#form_field").chosen().change( … );`

  Note: Prototype doesn't offer support for triggering standard browser events. Event.simulate is required to trigger the change event when using the Prototype version.

- ### Updating Chosen Dynamically

  If you need to update the options in your select field and want Chosen to pick up the changes, you'll need to trigger the "liszt:updated" event on the field. Chosen will re-build itself based on the updated content.

  - jQuery Version: `$("#form_field").trigger("liszt:updated");`
  - Prototype Version: `Event.fire($("form_field"), "liszt:updated");`

## Setup (for Prototype)

Using Chosen is easy as can be.

1. Download the plugin and copy the chosen files to your app.
2. Activate the plugin by creating a new instance of Chosen: new Chosen(some_form_field);
3. Disco.

orgia and The South Sandwich Islands">South Georgia and The South Sandwich Islands South Sudan Spain Sri Lanka Sudan Suriname Svalbard and Jan Mayen Swaziland Sweden Switzerland Syrian Arab Republic Taiwan, Republic of China Tajikistan Tanzania, United Republic of Thailand Timor-leste Togo Tokelau Tonga Trinidad and Tobago Tunisia Turkey Turkmenistan Turks and Caicos Islands Tuvalu Uganda Ukraine United Arab Emirates United Kingdom United States United States Minor Outlying Islands Uruguay Uzbekistan Vanuatu Venezuela Viet Nam Virgin Islands, British Virgin Islands, U.S. Wallis and Futuna Western Sahara Yemen Zambia Zimbabwe
Into This

## <optgroup> Support

Single Select with Groups
Multiple Select with Groups

## Selected and Disabled Support

Chosen automatically highlights selected options and removes disabled options.

Single Select
Multiple Select

## Default Text Support

Chosen automatically sets the default field text ("Choose a country...") by reading the select element's data-placeholder value. If no data-placeholder value is present, it will default to "Select Some Option" or "Select Some Options" depending on whether the select is single or multiple. You can change these elements in the plugin js file as you see fit.

`<select data-placeholder="Choose a country..." style="width:350px;" multiple class="chzn-select">`

Note: on single selects, the first element is assumed to be selected by the browser. To take advantage of the default text support, you will need to include a blank option as the first element of your select list.

## No Results Text Support

Setting the "No results" search text is as easy as passing an option when you create Chosen:

`New Chosen($("chzn_select_field"),{no_results_text: "No results matched"});`

## Allow Deselect on Single Selects

When a single select box isn't a required field, you can set `allow_single_deselect: true` and Chosen will add a UI element for option deselection. This will only work if the first option has blank text.

## Right to Left Support

Chosen supports right to left select boxes too. just add `"chzn-rtl"` in addition to `"chzn-select"` to your select tags and you are good to go.

`<select class="chzn-select chzn-rtl">`

Single right to left select
Multiple right to left select

## Change / Update Events

- ### Form Field Change

  When working with form fields, you often want to perform some behavior after a value has been selected or deselected. Whenever a user selects a field in Chosen, it triggers a "change" event* on the original form field. That let's you do something like this:

  `$("#form_field").chosen().change( … );`

  Note: Prototype doesn't offer support for triggering standard browser events. Event.simulate is required to trigger the change event when using the Prototype version.

- ### Updating Chosen Dynamically

  If you need to update the options in your select field and want Chosen to pick up the changes, you'll need to trigger the "liszt:updated" event on the field. Chosen will re-build itself based on the updated content.

  - jQuery Version: `$("#form_field").trigger("liszt:updated");`
  - Prototype Version: `Event.fire($("form_field"), "liszt:updated");`

## Setup (for Prototype)

Using Chosen is easy as can be.

1. Download the plugin and copy the chosen files to your app.
2. Activate the plugin by creating a new instance of Chosen: new Chosen(some_form_field);
3. Disco.