powmedia/backbone-forms — pull request #227 by sgarner (2013-04-18 01:10:09+00:00)
Title: Handle cases where a field value is a model

This pull request fixes a problem where, when the value of a field is a model, the field editor does not set the initial value correctly.

Some background:

I am using [Backbone Relational](http://backbonerelational.org/), and so my models can contain other models.

For example, let's say I have a Person model and a Location model, and each Person has a Location. The JSON would look like this:

```json
{"id":1,"name":"Fred Flintstone","location":{"id":123,"name":"Bedrock"}}
```

I want to have a Backbone Form with a Select editor to change the Person's Location. No problem, I just create a collection of Locations and set my Person schema like so:

```javascript
schema: {
location: {
type: 'Select',
options: locationsCollection
}
}
```

This correctly renders the select box, and the form submits and saves the new location value.

The only problem is, when the form is first displayed, the select box does not default to the current location value, as it tries to look for an option that equals the model object (which is impossible), instead of its `id`.

This pull request solves that problem.