toscawidgets/tw2.jqplugins.select2 — pull request #2 by bjonnh (2012-06-25 22:01:03+00:00)
Title: Adding a way to set initial values.

self.value : sqlalchemy collectionadapter or array of dicts
self.fields : contains fields of the model to be selected (avoid sending the whole data)

User must be careful to use the right results callback e.g:

```python
class FractionField(Select2AjaxSingleSelectField):
options = []
opts = dict(
multiple=True,
ajax=dict(
url="/fetch_fractions",
dataType="json",
data=twc.js_callback(
"""
```
```javascript
function (term, page) {
return {
q: term, // search term
};
}
```
```python
"""),
results=twc.js_callback(
"""
```
```javascript
function (data, page) {
return {results: data.data};
}
```
```python
"""),
),
formatSelection=twc.js_callback(
"""
```
```javascript
function (row) {
return row.code;
}
```
```python
"""),
formatResult=twc.js_callback(
"""
```
```javascript
function (row) {
return row.code;
}
```
```python
"""),
)
```
where row.code is the data to be displayed to the user.