Search code examples
javascriptextjsextjs4

extjs vtype: check value using another value in the same row


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!


Solution

  • 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.