Results 1 to 4 of 4

Thread: How to search/call a function with a "enter" in a textbox?

  1. #1
    Sencha Premium User
    Join Date
    Sep 2016
    Posts
    6

    Default How to search/call a function with a "enter" in a textbox?

    Hi!


    I want to call my search-function with a "enter"-command in a text box... i have tried this, but it doesn't work



    ...
    ...
    dockedItems: [{
    xtype: 'toolbar',
    dock: 'top',
    items: [
    {
    xtype: 'textfield',
    label: 'First Name',
    name: 'firstName',
    bind: {
    value: '{dfSearchFilterTextValue}'
    },
    listeners: {
    specialkey: function (field, e) {
    if (e.getKey() == e.ENTER) {
    // here i will call my search-function, but it dosen´t work
    this.fireEvent('onSearchByFilter', this);
    }
    }
    }
    }, {
    xtype: 'button',
    text: 'Suchen',
    listeners: {
    // search-function on button-click
    click: 'onSearchByFilter'
    }
    }]
    }]


    Br,

    Benjamin

  2. #2
    Sencha Premium User
    Join Date
    Feb 2009
    Location
    Glasgow, Scotland
    Posts
    418
    Answers
    17

    Default

    Your approach is correct but i the specialkey event handler you're firing a custom event whereas the click on the button is bound to a method (presumably) in your ViewController.

    You either need to have the button and enter press fire the same event (e.g. 'search') which the onSearchByFilter is then bound to. Or call the view controllers method directly from the key handler. I would favour the former.

    Have a look at this fiddle for an example:

    https://fiddle.sencha.com/#view/editor&fiddle/1v8d

  3. #3
    Sencha User
    Join Date
    Apr 2013
    Posts
    908
    Answers
    105

    Default

    You can also just use keyMap config:
    Code:
    keyMap: {
        ENTER: 'onLoginClick'
    }

  4. #4
    Sencha Premium User
    Join Date
    Feb 2009
    Location
    Glasgow, Scotland
    Posts
    418
    Answers
    17

    Default

    Of course! Forget my suggestion - go with Hakimio's answer. Much better!

Similar Threads

  1. Replies: 3
    Last Post: 2 Apr 2012, 4:39 AM
  2. how to call the function "onOk' by pressing the "enter" key on input?
    By bayat in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 13 Mar 2012, 10:02 AM

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
  •