# Methods

Select2 for WireBootstrap extends the [wire.ui.component](https://docs.wirebootstrap.com/wirebootstrap/reference/wire.ui/wire.ui.component) class.  As such, it inherits all its base methods.

The following methods are added to Select2 for WireBootstrap.

| Name             | Description                                                                                                                                                                                                                                                                     |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| clear            | Clears the current selection(s) and restores the list to its default state                                                                                                                                                                                                      |
| dirty(val)       | Returns whether there has been a change to the default selection. Optionally sets the dirty value to `val` if supplied.                                                                                                                                                         |
| getSelectedItem  | For single-select, returns the selected item from the config's data map                                                                                                                                                                                                         |
| getSelectedItems | For multi-select, returns all the selected items from the data map                                                                                                                                                                                                              |
| getSelectedRow   | For single-select, returns the row from the config `data` parameter in which the current selection resides.                                                                                                                                                                     |
| val(val)         | <p>Returns the currently selected value set in the config's <code>datamap.id.</code>This will be a single string or an array depending on whether <code>select2.multiple</code> is set.</p><p>Optionally sets the currently selected value to <code>val</code> if supplied.</p> |
| validate         | Validates the currently selected value using the rules set up in the config                                                                                                                                                                                                     |

The example below uses `getSelectedItem` to get the currently selected data map value from a list of users in the drop down per the `datamap` set up up in the configuration assuming `jembiid` was selected.

```javascript
const users = [
    { user: "bsimmons", name: "Ben Simmons", isGood: false },
    { user: "jembiid", name: "Joel Embiid" , isGood: true }

const select2 = new wire.select2().render("#select", {
    data: users,
    datamap: { id: "user", text: "name" }
});

...

const user = select2.getSelectedItem();

// user = { id: "jembiid", text: "Joel Embiid" }
```

The example below gets the `data` row for the currently selected value in the same drop down using `getSelectedRow`.

```javascript
...

const user = select2.getSelectedRow();

// user = { user: "jembiid", name: "Joel Embiid" , isGood: true }
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wirebootstrap.com/pro-pack/select2/methods.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
