I have been experimenting with this as well. I thought I'd show what I ended up with. I only ran this through the most basic test cases.

I added a new config option to form fields called 'bindToModel'. If you load a model using loadRecord() the formpanel then looks to the model and adds any validations it finds there if the 'bindToModel' property is set on the field.

BasicForm.LoadRecord uses record.data not record.raw - Why?

BasicForm.LoadRecord uses record.data not record.raw - Why?

I have a form that utilizes a HasMany association and find that the form initializes propperly when I alter loadRecord to use record.raw rather than record.data because record.data does not include any association elements. This seems to have changed between ExtJs4.0 and ExtJs4.0.2a. If anyone could provide advice on this I would greatly appreciate it. Additionally, if there is a reason for the change that might help my understanding, please share. Thanks.

updateRecord and events after failure

updateRecord and events after failure

I just came up with this idea for handling forms and server-side validation:
It would be great, if there was a form-event which is called if updateRecord fails, because the server returned an error. Then I would be able to display the form again, load the record and display form-errors returned by the server. The event I'm suggesting passes form, record and server-response to the handler.

Can this be implemented? I don't have any ideas how to do this.

Here's why I need this feature and why I think it would be great:
server-side validation is always available, since it's required, whereas client-side validation will always be optional. Therefore, it would be nice if my programs "fall back" to sever-side validation automatically as soon as client-side validation isn't available.

and on frontend side you have to handel not just success events, you should also check if you gote an error and if so do something like

Code:

this.getForm().markInvalid(_result.errors);

it's always good to work with both front and backend validation. frontend is faster for the user and can prevent annoying roundtrips for the user (send - error - send) he can see when he enters wrong values at realtime.
anyway the backend should validate anyhow, so that nobody can submit wrong data to your backend by hacking a bit js in the console.

I think it would be great if presentation of validation errors (from the server or from the model) were handled automatically by Ext.form.Basic/Panel and Ext.data.Model.
If not, maybe this would be a room for ux… to define something like ModelPlus and FormPanelPlus?
This would shorten the amount of project specific modifications/extensions that everybody working with MVC and Ext 4 probably has to do. I ended up overriding formPanel.loadRecord() and model.save() to accomplish this.

Some other comments:
I learned it the hard way that I need to set the trackResetOnLoad=true on the form.Basic. Otherwise things like isDirty() flag do not work properly.

Almost all form.Basic methods relevant to validation on (hasInvalidField() is one example) do not work with model validation.
I needed to query form directly to verify which fields are valid and which are not in my jasmine tests. I ended up using field.activeError property which seems not to care where the error came from. I do not know what it the best way to ask the form: are you presenting any errors to the user?

My so far experience with Ext 4 is very positive. Sure, there were (and are) rocky moments, but most of the time it was me who done something wrong.

Fix for multiple form fields for "bindToModel" solution.

Fix for multiple form fields for "bindToModel" solution.

The code from ykey works (thanks ykey!) great, except I found that if more than one form field was bound to the Model, and form.Basic.loadRecord was called on the form to set the initial form field values from those in the Model, then all except one form field (and the corresponding Model field) are cleared. This happens because the overridden onChange function in form.field.Base sets all the Model fields, via form.Basic.updateRecord, to the current values of the form fields whenever a form field is changed. When form.Basic.loadRecord is called and the first form field is updated and fires its onChange event, the overriden onChange function then sets the bound Model field values to the empty values of all the other form fields.

The following modified onChange function addresses this by only updating the individual Model field that is bound to the changed form field:

Model binding without changing the model

Model binding without changing the model

The examples above, in order to validate based on model rules, had to update the model.
if that model is from a store and to that store you also have other bound views (or grids) then whenever you make a modification in the form, that change is instantly reflected in other components that "display" this particular model.
I modified the code so that you can call .updateRecord only when you need to (for example a save button) but still have the validation work based on the model.
In addition, i monitor the the bound model so whenever it changes i call again loadRecord to reset the field values.