I found a problem in one of my applications under the 1.2.0 release with using revert().
In this simplified code, I create a grid with a ItemFileWriteStore behind it. If I edit the data in the grid, and then call revert(), the edits are reverted correctly. If I create a new row using store.newItem(), and then call revert() immediately, the new row disappears. But if I create a new row and THEN edit the field in the new row, when I use revert() my Grid disappears and says "Sorry, an error occurred." This behavior is consistent across FF2, FF3, and IE7.
At first I thought this was related to http://trac.dojotoolkit.org/ticket/7145 , but that bug is marked as fixed in 1.2 and the code looks correct.
Here is my code:
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<style type="text/css">
@import "js/dojo-release-1.2.0/dijit/themes/soria/soria.css";
@import "js/dojo-release-1.2.0/dojox/grid/resources/Grid.css";
@import "js/dojo-release-1.2.0/dojo/resources/dojo.css";
@import "js/dojo-release-1.2.0/dojox/grid/resources/soriaGrid.css";
</style>
<script type="text/javascript" src="js/dojo-release-1.2.0/dojo/dojo.js"
djConfig="parseOnLoad: true"></script>
<script type="text/javascript">
dojo.require("dojo.parser");
dojo.require("dojo.data.ItemFileWriteStore");
dojo.require("dijit.form.Button");
dojo.require("dojox.grid.DataGrid");
dojo.require("dijit.layout.BorderContainer");
dojo.require("dijit.layout.ContentPane");
dojo.require("dojox.grid._RowSelector");
var layout =
[
{name: 'Name', width:"30%", field: 'fname', editable: true},
{name: 'Email', width:"30%", field: 'emailaddr'},
];
var listStore = new dojo.data.ItemFileWriteStore({
url: "data/simple.json",
urlPreventCache: true
});
</script>
</head>
<body class="soria">
<div id="grid" dojoType="dojox.grid.DataGrid" jsId="listGrid"
structure="layout" query="{emailaddr:'*'}" store="listStore"
rowSelector="20px">
</div>
<div>
<button dojoType="dijit.form.Button" id="addButton">
<script type="dojo/method" event="onClick">
listStore.newItem({fname: "", emailaddr: "tim@nothing.com"});
</script>
Add New Recipient
</button>
</div>
<button dojoType="dijit.form.Button">
<script type="dojo/method" event="onClick">
listStore.revert();
alert("changes cancelled");
</script>
Delete Changes
</button>
</center>
</div> <!-- end center -->
</body>
And this is the JSON:
{
identifier: 'emailaddr',
items: [
{fname: 'Harold', emailaddr: 'harold@nothing.com'},
{fname: 'John', emailaddr: 'john@nothing.com'}
]
}Is this a bug, or am I using something incorrectly here?
Thank you,
Bill
