2

I've been learning ExtJS4 after having done quite a bit of dev in ExtJS3. I'm quite intrigued by the new class Ext.data.Models, but I would love to integrate these validations with the validation function in Ext.grid.Panel.

Can anyone point me in the direction of any examples of using the validations property of Ext.data.Model in a Grid panel?

I've tried adding the validations to the model and putting invalid values in the grid, but it doesn't seem to throw an errors or the normal red lines.

Any ideas?

Drew
  • 1,687
  • 5
  • 25
  • 46

2 Answers2

3

Model validation against grid data is not supported out of the box currently.

Here is a working extension for model validation against form fields though.

And here is an incomplete attempt for model validation against a grid (what you were going for).

egerardus
  • 11,316
  • 12
  • 80
  • 123
  • Ah, that would be why it didn't work for me. Hmm... so as I understand it then, would be that the only out-of-the-box purpose for the `validations` property, is for the `validate()` function called on an individual model? – Drew Jan 05 '12 at 05:53
  • I think validate() as you say should be used against individual models. This way in a grid context you could validate a new row before committing it or validate an edited row before sending it back to the store. – dougajmcdonald Jan 05 '12 at 08:17
  • Unfortunately that's right about model validation. But as @ajit.kumar mentioned you can use the extension for form validation (above) along with the extension for in-line row editing covered here: http://edspencer.net/2009/09/using-the-extjs-row-editor.html – egerardus Jan 05 '12 at 18:32
3

@Drew

The grid provides RowEditing and CellEditing plugins for row/cell editing. In the background these plugins use Form panel for the validation of the input. So, you can use the form panel extension that @Geronimo has mentioned along with the extensions of RowEditing and CellEditing classes and use them in your grid to validate the data entered in the grid against the model associated with the row. And since, the validate() method is on a model, which can be used to validate a complete row data or a particular cell data. In case you are looking for bulk validation, you can override the sync() method of the Ext.data.Store class to achieve that.

Ajit Kumar
  • 627
  • 5
  • 7