Selected field is blank when fetches a Backbone collection with Backbone-forms

390 views Asked by At

I use Backbone-forms for populate a Model. I have a select field with a backbone collection as options in the scheme. When this collection is empty, backbone-forms does a fetch, but the html of select appears blank.

When the collection is non empty always takes first option as value.

I would like the first time, when the collection is empty, it will shows the first value by default too.

class foo extends Backbone.Model
  schema:
    tag:
     type: 'select'
     options: new App.Collections.Tags
1

There are 1 answers

0
exussum On

Look at the example

http://jsfiddle.net/evilcelery/dW2Qu/

var user = new User({
    title: 'Mr',
    name: 'Sterling Archer',
    email: '[email protected]',
    birthday: new Date(1978, 6, 12),
    password: 'dangerzone',
    notes: [
        'Buy new turtleneck',
        'Call Woodhouse',
        'Buy booze'
    ]
});

These are the defaults.

In your case you would use something similar to

var options = new App.Collection.Tags;
class foo extends Backbone.Model
  schema:
    tag:
     type: 'select'
     options: options
for (first in options) break;
var Foo = new foo({tag:first});