Page 4 of 4 FirstFirst ... 234
Results 31 to 37 of 37

Thread: EditorGrid validation plugin

  1. #31
    Ext User
    Join Date
    Apr 2008
    Posts
    26
    Vote Rating
    0
      0  

    Default

    Hi Saki & MJ

    Thanks a lot for the information. I will go through these tuturials starting today.

    ~Rave

  2. #32
    Ext User
    Join Date
    Aug 2007
    Posts
    17
    Vote Rating
    1
      0  

    Default GridValidator within FormPanel using monitorResize

    Back to the GridValidator

    I changed the isCellValid function so that it ignores a currently focused field in the grid. Otherwise the line within the "if" clears out any typed in value. I am catching the "clientvalidation" event in FormPanel and using FormPanel's monitorResize (gray out submit button until valid). I extended both FormPanel and GridValidator. The code below could not be extended. I'll give more details if anyone has interest.
    PHP Code:
               isCellValid:function(colrow) {
                    if(!
    this.colModel.isCellEditable(colrow)) {
                        return 
    true;
                    }
                    var 
    ed this.colModel.getCellEditor(colrow);
                    if(!
    ed) {
                        return 
    true;
                    }
                    var 
    record this.store.getAt(row);
                    if(!
    record) {
                        return 
    true;
                    }
                    var 
    field this.colModel.getDataIndex(col);
    var 
    isValid false// if hasFocus, assume not yet valid
    if ( !ed.field.hasFocus ) {
                    
    ed.field.setValue(record.data[field]);
                    
    isValid ed.field.isValid(true);
    }
                    return 
    isValid;
                } 
    // end of function isCellValid 

  3. #33
    Ext User
    Join Date
    Jul 2007
    Location
    Florida
    Posts
    9,996
    Vote Rating
    8
      0  

    Default

    Quote Originally Posted by wolf View Post
    and using FormPanel's monitorResize (gray out submit button until valid).
    Do you mean monitorValid?

    Quote Originally Posted by wolf View Post
    The code below could not be extended.
    I don't understand that comment?

    Quote Originally Posted by wolf View Post
    I'll give more details if anyone has interest.
    Sure, post what you got. Any criticism only helps everyone?

  4. #34
    Sencha User
    Join Date
    Oct 2008
    Posts
    7
    Vote Rating
    0
      0  

    Default

    i added "validateModifiedOnly" for those who want check editet fields only:
    PHP Code:
    /**
     * EditorGrid validation plugin
     * Adds validation functions to the grid
     *
     * @author  Jozef Sakalos, aka Saki
     * @version 0.1
     *
     * Usage: 
     * grid = new Ext.grid.EditorGrid({plugins:new Ext.ux.plugins.GridValidator(), ...})
     */
    Ext.ux.plugins.GridValidator = function(config) {

        
    // initialize plugin
        
    this.init = function(grid) {
            
    Ext.apply(grid, {
                
    /**
                 * Checks if a grid cell is valid
                 * @param {Integer} col Cell column index
                 * @param {Integer} row Cell row index
                 * @param {Boolean} validateModifiedOnly true to validate modified fields only
                 * @return {Boolean} true = valid, false = invalid
                 */
                
    isCellValid:function(colrowvalidateModifiedOnly) {
                    if(!
    this.colModel.isCellEditable(colrow)) {
                        return 
    true;
                    }
                    var 
    ed this.colModel.getCellEditor(colrow);
                    if(!
    ed) {
                        return 
    true;
                    }
                    var 
    record this.store.getAt(row);
                    if(!
    record) {
                        return 
    true;
                    }
                    var 
    field this.colModel.getDataIndex(col);
                    if(!
    record.isModified(field)) {
                        return 
    true;
                    }
                    
    ed.field.setValue(record.data[field]);
                    return 
    ed.field.isValid(true);
                } 
    // end of function isCellValid

                /**
                 * Checks if grid has valid data
                 * @param {Boolean} editInvalid true to automatically start editing of the first invalid cell
                 * @param {Boolean} validateModifiedOnly true to validate modified fields only
                 * @return {Boolean} true = valid, false = invalid
                 */
                
    ,isValid:function(editInvalidvalidateModifiedOnly) {
                    var 
    cols this.colModel.getColumnCount();
                    var 
    rows this.store.getCount();
                    var 
    rc;
                    var 
    valid true;
                    for(
    0rowsr++) {
                        for(
    0colsc++) {
                            
    valid this.isCellValid(crvalidateModifiedOnly);
                            if(!
    valid) {
                                break;
                            }
                        }
                        if(!
    valid) {
                            break;
                        }
                    }
                    if(
    editInvalid && !valid) {
                        
    this.startEditing(rc);
                    }
                    return 
    valid;
                } 
    // end of function isValid
            
    });
        }; 
    // end of function init
    }; // GridValidator plugin end 

  5. #35
    Sencha User
    Join Date
    Jun 2012
    Posts
    2
    Vote Rating
    0
      0  

    Default How can i use in my code?

    any one please help me.

  6. #36
    Sencha User
    Join Date
    Jun 2012
    Posts
    2
    Vote Rating
    0
      0  

    Default how can i use this code ?

    Can i use this file as separate file ?

  7. #37
    Sencha User
    Join Date
    Mar 2016
    Posts
    1
    Vote Rating
    0
      0  

    Default

    I made some modification to get it worked in ExtJS4. Please have a try. Please send me mail if there is any problem.

    PHP Code:
    /** * EditorGrid validation plugin
     * Adds validation functions to the grid
     *
     * @author  Jozef Sakalos, aka Saki
     * @version 0.1
     *
     * Update History:
     * 2016-04-28: Alex Chen (pdckxd@gmail.com). Get it worked in ExtJS4.
     *
     * Note: You have to put this Javascript file into <your ext root folder>/ux/.
     *
     * Usage:
     * var plugin_instance = Ext.create('Ext.ux.GridValidator');
     */
    Ext.define('Ext.ux.GridValidator', {
        
    extend'Ext.AbstractPlugin',
        
    alias'plugin.gridvalidator'// xtype: gridvalidator

        
    constructor: function (config) {

            
    Ext.apply(thisconfig);

            
    this.callParent(arguments);
        },

        
    // initialize plugin
        
    init: function(grid) {
            var 
    me this;
            
    Ext.apply(grid, {
                
    isCellValidme.isCellValid,
                
    isValidme.isValid
            
    });
        },
        
    /**
         * Checks if a grid cell is valid
         * @param {Integer} col Cell column index
         * @param {Integer} row Cell row index
         * @param {Boolean} validateModifiedOnly true to validate modified fields only
         * @return {Boolean} true = valid, false = invalid
         */
        
    isCellValid: function (colrowvalidateModifiedOnly) {
            var 
    columns this.getView().getHeaderCt().getGridColumns();

            if (!
    columns[col].initialConfig.editor) {
                return 
    true;
            }
            var 
    record this.store.getAt(row);

            if (!
    record) {
                return 
    true;
            }

            var 
    field columns[col].dataIndex;

            if(
    validateModifiedOnly) {
                if (!
    record.isModified(field)) {
                    return 
    true;
                }
            }

            var 
    ed columns[col].getEditor(recordnull);
            if (!
    ed) {
                return 
    true;
            }

            
    ed.setValue(record.data[field]);
            return 
    ed.isValid();
        }, 
    // end of function isCellValid

        /**
         * Checks if grid has valid data
         * @param {Boolean} editInvalid true to automatically start editing of the first invalid cell
         * @param {Boolean} validateModifiedOnly true to validate modified fields only
         * @return {Boolean} true = valid, false = invalid
         */
        
    isValid: function (editInvalidvalidateModifiedOnly) {
            var 
    columns this.getView().getHeaderCt().getGridColumns();

            var 
    cols columns.length;
            var 
    rows this.store.getCount();
            var 
    rc;
            var 
    valid true;
            for (
    0rowsr++) {
                for (
    0colsc++) {
                    
    valid this.isCellValid(crvalidateModifiedOnly);
                    if (!
    valid) {
                        break;
                    }
                }
                if (!
    valid) {
                    break;
                }
            }
            
    // find first CellEditing plugin instance in grid.
            
    var found_plugin this.plugins.filter(function(p_item){
                return 
    p_item.$className == 'Ext.grid.plugin.CellEditing';
            });
            if (
    editInvalid && !valid && found_plugin.length 0) {
                
    found_plugin[0].startEditByPosition({rowrcolumnc});
            }
            return 
    valid;
        } 
    // end of function isValid
    }); 

Page 4 of 4 FirstFirst ... 234

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •