ExtJS 4 中的 RowEditor 数据验证

发布于 2024-12-29 18:01:55 字数 1693 浏览 5 评论 0原文

我设计了一个基于 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 中的行编辑添加验证功能?

提前致谢&干杯, 迈克尔

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

睡美人的小仙女 2025-01-05 18:01:55

集成 Ext.grid.panel 验证和Ext.data.Model.validations

上面的回复讨论了您可以遵循的方法

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

The above response talks about the approach that you can follow

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文