javascriptdom-eventssencha-touch-2

Sencha Touch 2 - "change" event listener for textfield


I would like to add an event listener for the change event on a textfield. I created a view which contains a form panel - everything works so far.

Now I tried to add a event listener to one of the textfields:

  items:[
        {
            xtype    :"textfield",
            name     :"field",
            label    :"field",
            required :true,
            listeners:{
                change:{
                    fn    : "onChangeHandler",
                    scope: this
                },
            }
    },

But it doesn't really work .. nothing happens. No errors and no function call. What am I doing wrong?

EDIT:

Tried another thing - directly within the item definition:

    {
    xtype    :"textfield",
    name     :"field",
    label    :"field",
    required :true,
    listeners:{
        change:{
            fn    :this.onChange
        },
        scope :this
    }
},

But then on change I got this error on console:

Uncaught TypeError: Cannot call method 'apply' of undefined


Solution

  • Try changing this:

    listeners:{
                            change:{
                                fn    : "onChangeHandler",
                                scope: this
                            },
                        }
    

    to this:

    listeners:{
                            change: this.onChangeHandler
                        }
    

    Updated: The most simple way is to set an id for your app.view.Login (say 'abc'), then:

    fn: function() {Ext.getCmp('abc').onEvent();},