ExtJS Monitor Keyboard events: Enter key to implement login function

Source: Internet
Author: User
Tags extend

First, we define a form with the following code:

The code is as follows Copy Code

Ext.define (' Demo.view.Viewport ', {
Extend: ' Ext.container.Viewport ',
items:[{
Xtype: ' Form ',
Title: ' ExtJS Monitor keyboard events ',
WIDTH:500,
height:400,
Margin: ' 100 0 0 200 ',
defaults:{
Xtype: ' TextField ',
WIDTH:300,
LABELWIDTH:120,
Margin: ' 20 0 0 30 '
},
items:[{
Fieldlabel: ' username ',
Name: ' username '
},{
Fieldlabel: ' Password ',
Name: ' Password ',
InputType: ' Password ',
Change configuration entry must be set to True, default false
Enablekeyevents:true
}],
bbar:[{
Text: ' Login ',
Action: ' Login '
},{
Text: ' Reset ',
Action: ' Reset '
}]
}]
});


Then, set the Listener event on the Password box, code:

The code is as follows Copy Code
ext.define (' Demo.controller.Controller ', {
    Extend: ' Ext.app.Controller ',
    init: function () {
     this.control ({
       ' viewport > form Textfield[name=password] ': {
       keypress:this.userlogin
      &NBSP}
     })
   },
    userlogin: function (b,e,eopts) {
     //e.getkey () is the number that gets the key, and 13 is the return enter
     if ( E.getkey () = {
      ext.msg.alert (' Hint ', ' you have pressed the return key, you can submit the form for login here ... ')
     }
   }
);

Enter a password, press ENTER, Pop-up prompts:

ExtJS keyboard Event details:
      1. First you set the input box that you want to listen to to allow keyboard events (enablekeyevents:true) to be used, or the keyboard event is unavailable;
      2. Use the Getkey () method to determine whether the key is set for yourself, the specific key number can refer to the ExtJS given API, and then do the specific action

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.