With Backbone.Forms is there a way to set the select editor option after loading a collection

575 views Asked by At

I have a form with a select editor type which uses a collection, but I have not found any way of setting the selected option after the data is loaded. I have not found anything in the documentation or any examples online.

...
country: { 
    title: 'Country',
    type: 'Select',
    options: function (callback) {
        var result = [];
        var states = new Countries();
        states.fetch({
            success: function (collection) {
                _.each(collection.models, function (model) {
                    result.push({ 'val': model.get('id'), 'label': model.get('name') });
                });
                callback(result);
            }
        });
    },
    validators: ['required']
},
...
1

There are 1 answers

2
exussum On BEST ANSWER

you can use

form.getEditor('country').setValue('YourVal')