4

I´ve designed an application based on the MVC Pattern. So I also defined my proxies, fields and validators in my model. Here for example is a model for a list of countries:

Model

Ext.define('LT.model.Country',{

    extend: 'Ext.data.Model',
    fields: [{name: 'id',type: 'int'},
             {name: 'name', type: 'string'},
    ],

    validations: [
        {type: 'length', field: 'name', min: 2}
    ],

    proxy: {
        type: 'rest',
        url: '/country',
        reader: {
            type: 'json'
        },
        writer: {
            type: 'json'
        }    
   }
});

And here is the store for using this model:

Store:

Ext.define('LT.store.Country', {
    extend: 'LT.base.store.Base',
    model:  'LT.model.Country'
});

The store is shown in a Grid Panel, where i use the RowEditor Plugin to enable adding and editing rows directly in grid view

Grid Panel:

    Ext.define('LT.view.country.List' ,{
    extend: 'Ext.grid.Panel',
    alias : 'widget.country-list',
    plugins: [
        Ext.create('Ext.grid.plugin.RowEditing', {
            clicksToEdit: 2,
            clicksToMoveEditor: 1
        })
    ],
    store : 'Country',

    columns: [
            {header: 'ID',  dataIndex: 'id', width: 50},
            {header: 'Name', dataIndex: 'name', flex: 3, editor: 'textfield'},

    ],
    tbar: [{
        xtype: 'button',
        action: 'add',
        text: 'Add'
    },{
        xtype: 'button',
        action: 'delete',
        text: 'Delete'
    }]

});

My problem now is, that the Validation Errors are not show if you edit data in grid view. If the data doesn´t match the validation criterias, then it´s not submitted to the proxy (which is fine), but the user also doesn´t get an error message, that the inserted data is invalid.

I found some (not really beautiful) workarounds - but maybe anyone knows another solution to add validation functionality to rowediting in extjs?

Thanks in advance & cheers, Michael

Michael
  • 2,966
  • 3
  • 30
  • 33

1 Answers1

2

Integrating Ext.grid.panel validation and Ext.data.Model.validations

The above response talks about the approach that you can follow

Community
  • 1
  • 1
Ajit Kumar
  • 627
  • 5
  • 7
  • Hi Ajit, Thanks for your response... But it also seems like a very hard way to do the validation. I now found out, that i can add the validation in the grid directly for the Fields. That´s also work twice, but better than coding validation in the controller for each grid... – Michael Jan 29 '12 at 15:40