Unless there is something in your route, which I cannot see, it looks like the problem is that , for one, you are not calling any action on the buttons that set the docId when they are clicked. Problem #2 is that your controller doesn't have a property called docTemplateId
yet. In order for your controller to take on the properties of your model, you need to pass it an instance of that model. If you passed a createRecord
as the model in your DocRoute
, then the value would be modifiable.
Here is the code that I used to make your example work, at least up until saving the record since I do not have your backend.
The jsbin is located here
App = Ember.Application.create();
App.ApplicationAdatper = DS.FixtureAdapter.extend({});
App.Router.map(function() {
// put your routes here
});
App.IndexRoute = Ember.Route.extend({
});
App.IndexController = Ember.ArrayController.extend({
tempDocId: null,
actions: {
addDoc: function (params) {
console.log(this.get('tempDocId'));
var docTemplateID = this.get('tempDocId');
var store = this.store;
var current_object = this;
var doc = current_object.store.createRecord('doc', {
docTemplateID:docTemplateID
});
doc.save();
return true;
},
setDocId: function (param) {
this.set('tempDocId', param);
console.log(this.get('tempDocId'))
}
}
});
App.Doc = DS.Model.extend({
docTemplateID: DS.attr('number')
});
And the template:
<script type="text/x-handlebars" data-template-name="index">
<form {{action "addDoc" on="submit"}} id="addDoc" name="addDoc">
<div>
<button value="1" {{action 'setDocId' 1}}> 1 </button>
<button value="2" {{action 'setDocId' 2}}> 2 </button>
</div>
<button type="submit" class="submit"> Add</button>
</form>
</script>
I hope this helps!