如何在 ExtJS 网格验证中显示错误?

How to display error in validation for ExtJS grid?

我正在使用 ExtJS 构建一个允许轻松编辑数据库的 Web 应用程序。

我想限制某些字段的字符数。所以我添加了 validation 如下所示。好像行得通,不符合要求就不会持久化数据。但是没有消息告诉用户出了什么问题。

Ext.onReady(function() {
    var cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
        clicksToEdit : 1
    });

    var toolbar = Ext.create('Ext.toolbar.Toolbar', {
      // [snip]
    });

    // Set up a model to use in our Store
    var mysource = Ext.define('Source', {
        extend : 'Ext.data.Model',
        fields : [ {
            name : 'id',
            type : 'int'
        }, {
            name : 'firstname',
            type : 'string'
        } ],
        validations: [{type: 'length', field: 'firstname', max: 10}]
    });


    var myStore = Ext.create('Ext.data.JsonStore', {
        model : 'Source',
        idProperty : 'id',
        proxy : {
            type : 'ajax',
            api : {
              // [snip]
            },
            reader : {
                type : 'json',
                root : 'data',
                successProperty: 'status'
            }
        },

        autoLoad : true
    });

    myStore.load();
    Ext.tip.QuickTipManager.init();

    // create the Grid
    var grid = Ext.create('Ext.grid.Panel', {
        plugins : [ Ext.create('Ext.grid.plugin.CellEditing', {
            clicksToEdit : 1
        }) ],
        dockedItems : toolbar,
        store : myStore,
        stateful : true,
        stateId : 'stateGrid',
        columns : [ {
            text : 'ID',
            flex : 1,
            sortable : true,
            dataIndex : 'id'
        }, {
            text : 'Name',
            flex : 1,
            sortable : true,
            dataIndex : 'firstname',
            editor : {
                xtype : 'textfield'
            }
        } ],
        height : 350,
        width : 600,
        title : 'View / Edit Names',
        renderTo : 'nameGrid'
    });
});

我希望所有这些都是明智的,我已经删除了不相关的内容。我不在乎错误消息有多漂亮,但我需要在验证失败的情况下显示一条消息(在这种情况下名称太长)。

有一个 属性 lengthMessage 用于验证。我想这就是您要找的。

就个人而言,我没有对模型使用验证。 我在表单字段和编辑器上使用了 VTypes,消息总是显示在那里。