Results 1 to 4 of 4

Thread: keyup override function not work

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

    Default keyup override function not work

    hello all
    this is my code :in this code keyup( keyup: function(e)) not work and any action
    my extjs version is 4.1

    Code:
    Ext.require([
        '*'
    ]);
    Ext.Loader.setPath('Ext.ux', '/extjs/examples/ux');
    
    
    Ext.onReady(function() {
       console.log('hi');   
       
        Ext.define('User', {
          extend: 'Ext.data.Model',
          fields: ['id', 'name', 'email']
        });
    
        var myStore = Ext.create('Ext.data.Store', {
            model: 'User',
            proxy: {
                type: 'ajax',
                url : '/cloud/GetdataXml',
                reader: {
                    type:  'xml',
                    record:'user',
                    root:  'users'
                }
            }
        });
        myStore.load();
        console.log('hi2');   
         var grid=Ext.create('Ext.grid.Panel', {
            store:myStore ,
            columns:[{
                dataIndex: 'id',
                width: 50,
                text: 'ID'
            },{
                dataIndex: 'name',
                width: 100,
                text: 'name'
            },{
                dataIndex: 'email',
                width: 150,
                text: 'Address'
            }]/*,
            plugins:[{
                ptype: 'rowexpander',
                rowBodyTpl : [
                     '<p>{email}</p>'
                ]
            }]*/,        
            height: 400,
            width: 400
        });
        console.log('hi3');    
        
        var form=Ext.create('Ext.form.Panel', {
            title: 'User Form',        
            height: 450,
            width: 500,
            bodyPadding: 10,
            defaultType: 'textfield',
            items: [
                {
                    fieldLabel: 'Search',
                    name: 'query',
                    allowBlank:true ,
                    listeners: {
                            // call this function on event keyup
                            keyup: function(e)
                            {
                                    alert("hello from keyup");
                                    var theQuery=e.getValue();
                                    console.log('keyup'+theQuery); 
    
                            }
                        }                
                },
                {
                    xtype: 'textfield',
                    name: 'name',
                    fieldLabel: 'Name',
                    allowBlank: true  // requires a non-empty value              
                },
                grid
                
            ],
            renderTo:'results'
        });
        
        Ext.override(Ext.form.Field, {
          onKeyUp : function(e) {
              this.fireEvent('keyup', this, this);
          },  
          fireKey : function(e) {
                if(((Ext.isIE && e.type == 'keydown') || e.type == 'keypress') && e.isSpecialKey()) {
                    this.fireEvent('specialkey', this, e);
                    console.log('fireKey');   
                }
                else {
                    this.fireEvent(e.type, this, e);
                    console.log('else');   
                }
          }
          , initEvents : function() {
                this.el.on("focus", this.onFocus,  this);
                this.el.on("blur", this.onBlur,  this);
                this.el.on("keydown", this.fireKey, this);
                this.el.on("keypress", this.fireKey, this);
                this.el.on("keyup", this.fireKey, this);
                this.originalValue = this.getValue();
            }
        });
        form.show()
    });

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,412
    Vote Rating
    1288
      0  

    Default

    Set enableKeyEvents to true on the field.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Mar 2012
    Posts
    7
    Vote Rating
    0
      0  

    Default not work

    this code not work keyup override and not any action

    Code:
    Ext.require([
        '*'
    ]);
    Ext.Loader.setPath('Ext.ux', '/extjs/examples/ux');
    
    
    Ext.onReady(function() {
       console.log('hi');   
       
        Ext.define('User', {
          extend: 'Ext.data.Model',
          fields: ['id', 'name', 'email']
        });
    
    
    
    
    
    
        var myStore = Ext.create('Ext.data.Store', {
            model: 'User',
            proxy: {
                type: 'ajax',
                url : '/cloud/GetdataXml',
                reader: {
                    type:  'xml',
                    record:'user',
                    root:  'users'
                }
            }
        });
        myStore.load();
        console.log('hi2');   
         var grid=Ext.create('Ext.grid.Panel', {
            store:myStore ,
            columns:[{
                dataIndex: 'id',
                width: 50,
                text: 'ID'
            },{
                dataIndex: 'name',
                width: 100,
                text: 'name'
            },{
                dataIndex: 'email',
                width: 150,
                text: 'Address'
            }],        
            height: 400,
            width: 400
        });
        console.log('hi3');    
        
        var form=Ext.create('Ext.form.Panel', {
            title: 'User Form',        
            height: 450,
            width: 500,
            bodyPadding: 10,
            defaultType: 'textfield',
            items: [
                {
                    enableKeyEvents: true,
                    fieldLabel: 'Search',
                    name: 'query',
                    allowBlank:true ,
                    listeners: {
                            // call this function on event keyup
                            keyup: function(e)
                            {
                                    console.log('keyup up'); 
                                    var theQuery=e.getValue();
                                    console.log('keyup'+theQuery);                                 
                            }
                        }                
                },
                {
                    xtype: 'textfield',
                    name: 'name',
                    fieldLabel: 'Name',
                    allowBlank: true  // requires a non-empty value              
                },
                grid
                
            ],
            renderTo:'results'
        });
        
        Ext.override(Ext.form.Field, {
          onKeyUp : function(e) {
              this.fireEvent('keyup', this, this);
          },  
          fireKey : function(e) {
                if(((Ext.isIE && e.type == 'keydown') || e.type == 'keypress') && e.isSpecialKey()) {
                    this.fireEvent('specialkey', this, e);
                    console.log('fireKey');   
                }
                else {
                    this.fireEvent(e.type, this, e);
                    console.log('else');   
                }
          }
          , initEvents : function() {
                this.el.on("focus", this.onFocus,  this);
                this.el.on("blur", this.onBlur,  this);
                this.el.on("keydown", this.fireKey, this);
                this.el.on("keypress", this.fireKey, this);
                this.el.on("keyup", this.fireKey, this);
                this.originalValue = this.getValue();
            }
        });
        form.show()
    });

  4. #4
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,412
    Vote Rating
    1288
      0  

    Default

    This worked just fine:

    Code:
    {
        xtype           : 'textfield',
        fieldLabel      : 'test',
        enableKeyEvents : true,
        listeners       : {
            keyup : function(field, e) {
                console.log(field.getValue());
            }
        }
    }
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

Tags for this Thread

Posting Permissions

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