View Full Version : ExtJS MVC, Models, Stores and Server side validation errors

3 Oct 2011, 6:56 PM
ExtJS newb here.... I am trying out the new MVC approach in ExtJS4 with rails, and I have a form that has client side ('name must be longer than 2') and server side validations ('name must be unique', etc). The client side validations are working, but using the store.insert, I am not sure how to get the server side errors back into my form.

Here is the code for my create button (from the Ext MVC controller)

createItem: function(button) {
var win = button.up('window');
form = win.down('form');
values = form.getValues();
Ext.data.StoreManager.lookup('Users').insert(0, new AdminUI.model.User(values));

Where can I put the success/failure code to capture and mark the fields invalid?

or should I skip the store insert and use the model proxy directly, and then call a store reload?

3 Oct 2011, 7:38 PM
Perhaps this may help:


It has built-in support for server-side validation of fields. You could submit the form and only add the record to the store once you get a success.

4 Oct 2011, 9:34 AM
Hmmm. not sure if this is the same thing. does this use the model/store approach with the REST proxy, or just a standard POST, and then I have to tell the store to resync.

4 Oct 2011, 1:27 PM
You're correct, it sends a direct POST and does not go through the REST proxy of the store. However, you can configure the request as you see fit (from the server's perspective it can be made to appear identical to a REST proxy).

Your current technique seems to be adding unnecessary levels of indirection to me. Getting validation feedback to the the form is made more complicated because you've put the data through a model/store first. If you just submit the form directly it's trivial to get validation back. You can then add it to the store once you've confirmed it is valid.

I'm sure you could make it work the way you're doing it at the moment, just feels like you're making things harder for yourself.