mongeta
mongeta

Reputation: 2301

Ember Select changes but my model is still 'no dirty'

I have two models, MyModel and MyOptions.

MyModel has a myValue property belongsTo('myOption), and myName('string').

In the view, I have an input for myName and a select with possible values of the model MyOptions.

When I select a new related row, I expect myModel to be 'dirty'. If I change myName, myModel gets 'dirty' (correctly).

What I'm doing wrong?

Thanks,

See this jsfiddle for the code

window.App = Ember.Application.create();
App.ApplicationAdapter = DS.FixtureAdapter.extend();

App.IndexController = Ember.ObjectController.extend({

});

App.IndexRoute = Ember.Route.extend({
    model: function() { 
        return Ember.RSVP.hash({
            myModel: this.store.find('myModel', 1),
            myOptions: this.store.find('myOption')
        });
    },
});

App.MyOption = DS.Model.extend({
    name: DS.attr('name')
});

App.MyOption.FIXTURES = [
    { name: 'User a', id: 1 }, 
    { name: 'User b', id: 2 },
    { name: 'User c', id: 3 },
];

App.MyModel = DS.Model.extend({
    myValue: DS.belongsTo('myOption'),
    myName: DS.attr('string')
});

App.MyModel.FIXTURES = [
    { 
        id: 1,
        myValue: 2
    }
];


<script type="text/x-handlebars" data-template-name="index">
    <h1>Test</h1>
    <lablel>My Value</label>{{input value=myModel.myValue.id}}
    <lablel>My Name</label>{{input value=myModel.myName}}
    {{view "select" 
        content=myOptions 
        selectionBinding=myModel.myValue 
        optionLabelPath="content.name"}}

    {{myModel.isDirty}}
</script>

Upvotes: 2

Views: 113

Answers (2)

Kit Sunde
Kit Sunde

Reputation: 37075

ember-data doesn't handle dirtyness for relationships, yet. You would need to implement it in user-space.

Upvotes: 2

Steve H.
Steve H.

Reputation: 6947

Instead of using selectionBinding, you should use value:

{{view "select" 
    content=myOptions 
    value=myModel.myValue 
    optionLabelPath="content.name"}}

Upvotes: 0

Related Questions