Reputation: 665
I am unable to select a default value in an ember select. Here is what the code looks like
Models:
rfwa.Field = DS.Model.extend({
Name: DS.attr('string'),
FieldTypeId: DS.attr('number'),
FieldType: DS.belongsTo('fieldType'),
});
rfwa.FieldType = DS.Model.extend({
Name: DS.attr('string')
});
Route:
rfwa.FieldRoute = Ember.Route.extend({
model: function (params) {
var route = this;
return Ember.RSVP.hash({
field: route.store.find('field', params.field_id),
fieldTypes: route.store.find('fieldType')
});
},
setupController: function (controller, model) {
controller.set('fieldTypes', model.fieldTypes);
controller.set('model', model.field);
}
});
Template:
<script type="text/x-handlebars" data-template-name="Field">
{{input value=model.Name class="form-control" id="Name"}}
{{view "select" content=fieldTypes optionValuePath="content.id" optionLabelPath="content.Name" value=model.FieldTypeId classNames="form-dropdown"}}
</script>
I have fiddled with a lot of possibilities using selection and value in the view. Creating functions that returns a fieldType for selection. So far, nothing has worked. there has to be something I am doing wrong.
I am using Ember 1.12.1 with Ember-data 1.0.0-beta18.
Currently with what I have pasted, it sets my model.FieldTypeId to undefined when the page loads.
Upvotes: 0
Views: 363
Reputation: 665
The reason why it didn't work is because the id from DS.Model is a string while my FieldTypeId was a number. I changed my model to
FieldTypeId: DS.attr('string')
And this solved all my problems.
Upvotes: 0
Reputation: 31
Not sure if you had a controller defined but if you are setting properties on it you should define one with those properties at least. I set up a jsbin to show what you can do as far as setting the default selection and binding it:
http://emberjs.jsbin.com/qijudidade/1/edit?html,js,output
Upvotes: 1