extjs vtype:使用同一行中的另一个值检查值

发布于 2024-12-01 07:02:47 字数 554 浏览 2 评论 0原文

我有一个 Ext.grid.Panel,我想验证用户输入:有一个名为 delete 的字段和一个名为 string 的字段。 delete 的有效输入是一个数字,该数字不能大于同一行中string 字段的长度。我已经知道如何使用 vtype 所以现在我

delete : function(val, field){
            var expr = new RegExp("^[-]?[0-9]*[\.]?[0-9]*$");
            var num = expr.test(val);
            if (!num) return false; //can't be not a number
            else{
                 //have no idea...
            }
        }

不知道如何访问同一行的 string 值。

希望它很清楚。谢谢!

I have an Ext.grid.Panel and i want to validate user input: there is a field named delete and a field named string. Valid input for delete is a number, which can't be greater than the length of a string field in the same row. I already know how to use vtype so now i have

delete : function(val, field){
            var expr = new RegExp("^[-]?[0-9]*[\.]?[0-9]*$");
            var num = expr.test(val);
            if (!num) return false; //can't be not a number
            else{
                 //have no idea...
            }
        }

I have no idea how to access string value for the same row.

Hope it's quite clear. Thanks!

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

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

发布评论

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

评论(4

回忆躺在深渊里 2024-12-08 07:02:47

如果将编辑器定义为变量,实际上会更简单、更清晰,您只需在字段验证器方法中引用它并获取活动记录,例如:

// create editor as a variable
var cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
    clicksToEdit: 1,
    autoCancel: false
});

// referring to the edited record in the validator function
    {
        xtype: 'datecolumn',
        header: 'Comp Date',
        dataIndex: 'comp_date',
        width: 100,
        format: 'j-M-Y',
        editor: {
            xtype: 'datefield',
            format: 'j-M-Y',
            validator: function(value) {
                var record  = cellEditing.getActiveRecord(); // get active record
                if (Ext.Date.parse(value, 'j-M-Y') < record.get('start_date')) {
                    return 'Cannot complete before start date';
                } else return true;
            }
        }
    }

It's actually much simpler and cleaner if you define your editor as a variable, you can just refer to it in the fields validator method and get the active record, for example:

// create editor as a variable
var cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
    clicksToEdit: 1,
    autoCancel: false
});

// referring to the edited record in the validator function
    {
        xtype: 'datecolumn',
        header: 'Comp Date',
        dataIndex: 'comp_date',
        width: 100,
        format: 'j-M-Y',
        editor: {
            xtype: 'datefield',
            format: 'j-M-Y',
            validator: function(value) {
                var record  = cellEditing.getActiveRecord(); // get active record
                if (Ext.Date.parse(value, 'j-M-Y') < record.get('start_date')) {
                    return 'Cannot complete before start date';
                } else return true;
            }
        }
    }
夏有森光若流苏 2024-12-08 07:02:47

您应该处理 validateedit( Ext.grid.plugin.Editing editor, Object e, Object eOpts ) 事件

第二个参数 e 包含对已编辑记录 (e.record) 的引用。您可以使用此记录来获取两个字段(stringdelete)并相应地执行验证。
false 分配给 e.cancel 将取消编辑。

You should handle validateedit( Ext.grid.plugin.Editing editor, Object e, Object eOpts ) event.

The second argument, e, contains reference to the record that is edited (e.record). You could use this record to get both fields(string and delete) and perform validation accordingly.
Assigning false to e.cancel will cancel the editing.

愿与i 2024-12-08 07:02:47

好吧,有一个解决方法,但它很丑陋:

rowEditing.on({
    scope : this,
    afteredit : function(roweditor, changes, record, rowIndex) {
        var can_save = true;
        var records = store.getRange();
        for(var i = 0; i < records.length; i++) {
            if(records[i].data['delete'] >= records[i].data['string '].toString().length) {
                Ext.MessageBox.alert('Input error', "blahblah");
            }

well, there's a workaround, but it's ugly:

rowEditing.on({
    scope : this,
    afteredit : function(roweditor, changes, record, rowIndex) {
        var can_save = true;
        var records = store.getRange();
        for(var i = 0; i < records.length; i++) {
            if(records[i].data['delete'] >= records[i].data['string '].toString().length) {
                Ext.MessageBox.alert('Input error', "blahblah");
            }
開玄 2024-12-08 07:02:47

我通过以下方式访问该插件:

this.ownerCt.ownerCmp.plugins

这使您可以访问 cellEditing 插件,从那里您可以执行以下操作:

var record = plugin.getActiveRecord(); 

I accessed the plugin the following way:

this.ownerCt.ownerCmp.plugins

That gives you access to the cellEditing plugin and from there you could do a:

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