Results 1 to 6 of 6

Thread: Having trouble with KeyMap and having work with Enter Button

  1. #1
    Sencha User
    Join Date
    Aug 2017
    Posts
    44
    Answers
    1
    Vote Rating
    1
      0  

    Default Answered: Having trouble with KeyMap and having work with Enter Button

    I am having some trouble understanding how to use KeyMap in my code. All I want to do is console the text I have written.

    The check Enter button has an even of Click and the function name is CheckEnter. The click works fine but I want to work with the Enter Key.

    I am looking at the KeyMap object I found on Config for button, but at this point I just don't know how to use it. Any help would be greatly appreciated.

    Code:
        controller: 'myfieldset',
        viewModel: {
            type: 'myfieldset'
        },
        height: 250,
        width: 400,
        title: 'My Fields',
        items: [
            {
                xtype: 'textfield',
                anchor: '100%',
                fieldLabel: 'Label'
            },
            {
                xtype: 'button',
                text: 'CheckEnter',
                listeners: {
                    click: 'checkEnter'
                }
            }
        ]
    });
    This is what I have so far. I know that I need to use keyMap. Just don't know how to implement the Enter key to fire the checkEnter
    function.

    Code:
    Ext.define('BreakEnter.view.MyFieldSetViewController', {
        extend: 'Ext.app.ViewController',
        alias: 'controller.myfieldset',
    
    
        checkEnter: function(button, e, eOpts) {
            console.log('Button clicked. Does Enter work?');
        }
    });
    Thanks for the help in advance!

  2. For the textfield enableKeyEvents and then you can listen for the keyup event:

    http://docs.sencha.com/extjs/6.5.2/c...nableKeyEvents
    http://docs.sencha.com/extjs/6.5.2/c...ml#event-keyup

    Bryan

  3. #2
    Sencha - Support Team bjdurham85's Avatar
    Join Date
    Mar 2014
    Posts
    956
    Answers
    55
    Vote Rating
    21
      0  

    Default

    Hi--,

    Thanks for the info. So when you hit the enter button anywhere in your form (i.e. they're in a textfield) or just when the button? **You might also take a look at this forum thread, seems relevant:

    https://www.sencha.com/forum/showthread.php?310376

    Bryan

  4. #3
    Sencha User
    Join Date
    Aug 2017
    Posts
    44
    Answers
    1
    Vote Rating
    1
      0  

    Default

    Yes, the text is in the text field at this time. When I click the button it will console the two text fields I want to be seen, but I want to have the enter button call the same ClickButton. How do I do that?

    So my click event work when I click button. I want the click event to also be called I click the enter button.

    Hopefully that is clear enough.

    Thanks, Bryan.

    Robzdoom

  5. #4
    Sencha - Support Team bjdurham85's Avatar
    Join Date
    Mar 2014
    Posts
    956
    Answers
    55
    Vote Rating
    21
      1  

    Default

    For the textfield enableKeyEvents and then you can listen for the keyup event:

    http://docs.sencha.com/extjs/6.5.2/c...nableKeyEvents
    http://docs.sencha.com/extjs/6.5.2/c...ml#event-keyup

    Bryan

  6. #5
    Sencha User
    Join Date
    Aug 2017
    Posts
    44
    Answers
    1
    Vote Rating
    1
      0  

    Default

    Ok but on the button I am grabbing the values from each text. I just want the button to be clicked upon hitting enter.

    Thanks for the help you've been great.

    Regards,

    robzdoom

  7. #6
    Sencha User
    Join Date
    Aug 2017
    Posts
    44
    Answers
    1
    Vote Rating
    1
      0  

    Default

    Screen Shot 2017-12-01 at 11.56.46 AM.jpg

    As you can see here, upon clicking on click, I get values of both textfields because I created a click Event on SignIn Button and i use getValue() and it works. I want the same event to work with just hitting Enter. How do I do that?

Similar Threads

  1. newbie question on keymap : a keymap put on a Field doesn't work
    By flamant in forum Ext 3.x: Help & Discussion
    Replies: 3
    Last Post: 12 May 2011, 11:54 AM
  2. Keymap catch enter ignores shift/ctrl/alt
    By mdissel in forum Ext 2.x: Help & Discussion
    Replies: 13
    Last Post: 10 Mar 2009, 9:34 AM
  3. keyMap for handling Enter and Ctrl + Enter
    By soad in forum Ext 1.x: Help & Discussion
    Replies: 1
    Last Post: 14 Apr 2007, 4:52 AM

Posting Permissions

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