I've got ember (1.0.0-pre2) view which has a form and a button. The form is bound to a view class which allows populating form inputs and gathering entered values. Now on button click I want to create a dto object from the form values and send it to controller. The button html is as follows
<input type="submit" value="Add" data-icon="plus" {{action addReport view.report target="controller"}} />
The view code is
ContentView: baseView.extend({
task: null, //initialized when form is filled in
report: function () {
var task = this.get('task');
if (task == null)
return null;
return reportModel.create({
taskId: task.id
});
}.property()
})
The controller code is
DayController: ember.Controller.extend({
addReport: function (evt) {
console.log(evt.context);
}
})
When I run the code, the event context is null. When I look in the debugger, the report computed property executed only once, when the view is rendered. On button click the computed property is not evaluated - controller method is invoked right away.
Very similar construction works fine in the same application but for different view and the method is in the router, not controller:
<a href="#" {{action changeDate view.prevDate href=true}}>Prev</a>
view:
HeaderView: baseView.extend({
prevDate: function () {
return addDays(this.get('_dataSource').date, -1);
}.property()
})
What is wrong with the button, why it doesn't work as opposed to the link?
var task = this.get('task')in the report property function-- that meanstaskis a property onContentViewin your code but just omitted from the example? - chrixiantaskis the property of the ContentView. I updated the code in the question. - achekh