javascript - How to create shortcut keys in extjs - Stack Overflow

I write this code for submit on Enter{fieldLabel : 'Password',name : 'j_password',i

I write this code for submit on Enter

 {
    fieldLabel : 'Password',
    name : 'j_password',
    inputType : 'password',
    allowBlank : false,
    listeners : {
        'render' : function(cmp) {
                 cmp.getEl().on('keypress', function(e) {
                      if (e.getKey() == e.ENTER) {
                          submitform();
                      }
                 });
         }
     }
   }

What change do I need to do for shortcut keys Like Save(Ctrl + S),Paste(Ctrl +P), Open (Ctrl + O), Exit(Ctrl +X)?

I write this code for submit on Enter

 {
    fieldLabel : 'Password',
    name : 'j_password',
    inputType : 'password',
    allowBlank : false,
    listeners : {
        'render' : function(cmp) {
                 cmp.getEl().on('keypress', function(e) {
                      if (e.getKey() == e.ENTER) {
                          submitform();
                      }
                 });
         }
     }
   }

What change do I need to do for shortcut keys Like Save(Ctrl + S),Paste(Ctrl +P), Open (Ctrl + O), Exit(Ctrl +X)?

Share Improve this question edited Oct 29, 2019 at 22:25 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jul 23, 2013 at 5:24 jayeshjayesh 2,4927 gold badges44 silver badges80 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

You need to write appropriate handler to do the job using KeyMap. Ext 4 code snippet may be as follows -

Ext.onReady(function () {
    var map = new Ext.util.KeyMap(document,{                
            key: [VALUES-ASCII], // this works,
            fn: function(){ alert('key was pressed.!'); }
        }
    );
});

This may Help

I think, You will solve your problem by this code

I Give many ways.

You choose suitable one from binding:[{}]

                scope     :  this,
                listeners : {                       
                    afterrender: function(window, options) {
                        this.keyNav = new Ext.util.KeyMap({
                            target: window.el,
                            binding: [{
                                key: [10,13],
                                fn: function(){
                                    alert("Return was pressed");
                                }
                            }, {
                                key: "abc",
                                fn: function(){                                    
                                    alert('a, b or c was pressed');
                                }
                            }, {
                                key: "\t",
                                ctrl:true,
                                fn: function(){
                                     submitform();//'Control + tab was pressed
                                }
                            }, {
                                key: "m",
                                ctrl:true,
                                fn: function(){
                                     submitform();//'Control + m was pressed
                                }
                            }],
                            scope: this
                        }); 
                    }
                }

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744742373a4591102.html

相关推荐

  • javascript - How to create shortcut keys in extjs - Stack Overflow

    I write this code for submit on Enter{fieldLabel : 'Password',name : 'j_password',i

    1天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信