1
Vote

New items which are deleted are still posted to server

description

If you add an item and then delete it from the view, the item is still posted to the server, without a delete also being sent. In DataSet.SaveAll it walks the NewItems array and does the post via the Create function. Wrapping the call to Create with if(this.NewItems[i].EntityState() != spa.entityStates.removed) fixes the issue, but there may be a better way.

comments

rposener wrote Jul 17, 2012 at 2:13 PM

Can you provide an example of how to duplicate this issue? That would help me a bunch before I spend a bunch of time trying to figure out how to repro this.

Thanks,

Ryan

dacendale wrote Jul 17, 2012 at 2:55 PM

Thanks for the quick reply. Here's a repo created from stripping down what I'm using:
Using a form something like:
<table> <tbody data-bind="foreach: {data: Items, afterRender: onAfterRender}"> <tr> <td><input data-bind="click: $parents[0].DeleteRotation" type="button" value="-"/></td> <td><input data-bind="text: Entity.Name" /></td> </tr> </tbody> </table> <input data-bind="click: AddRotation" type="button" value="+"/>
<input data-bind="click: Save" type="button" value="Save"/>

You'll get a table of data you are editing. The AddRotation and DeleteRotation properties map to:
self.addRotation = function () {
    self.view.AddItem(new spa.dataEntity({
        Name: 'Rotation'
    }));
};

self.deleteRotation = function (item) {
    self.view.DeleteItem(item);
};
With buffered changes, when you press add to create a template item and then decide you don't want it, so press the delete button beside it, when you press save (which just calls SaveAll, not shown) you can see in fiddler that the template item is posted to the server.
I can email a complete solution if necessary.

wrote Feb 14, 2013 at 6:21 PM