【问题标题】:RowEditor Data Validation in ExtJS 4ExtJS 4 中的 RowEditor 数据验证
【发布时间】:2012-02-21 13:00:25
【问题描述】:

我设计了一个基于 MVC 模式的应用程序。所以我还在我的模型中定义了我的代理、字段和验证器。例如,这里是一个国家列表的模型:

型号

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'
        }    
   }
});

这里是使用这个模型的商店:

商店:

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

商店显示在网格面板中,我使用 RowEditor 插件 可以直接在网格视图中添加和编辑行

网格面板:

    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'
    }]

});

我的问题现在是,如果您在网格视图中编辑数据,验证错误不会显示。如果数据不符合验证标准,则它不会提交给代理(这很好),但用户也不会收到错误消息,即插入的数据是无效。

我找到了一些(不是很漂亮)的解决方法 - 但也许有人知道另一种解决方案,可以在 extjs 中为行编辑添加验证功能?

提前感谢和欢呼, 迈克尔

【问题讨论】:

    标签: validation extjs model extjs4 store


    【解决方案1】:

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

    以上回复谈到了您可以遵循的方法

    【讨论】:

    • 嗨,Ajit,感谢您的回复...但这似乎也是一种非常困难的验证方式。我现在发现,我可以直接在网格中为字段添加验证。这也可以工作两次,但比在控制器中为每个网格进行编码验证要好...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-06
    • 1970-01-01
    • 2016-03-01
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    • 2011-09-01
    相关资源
    最近更新 更多