mshwf
mshwf

Reputation: 7449

Add onclick function to a component in ExtJS?

I want to add a click listener to a hyperlink that calls the function from the controller:

View:

 {
                xtype: 'component',
                autoEl:{
                html: '<a href="#">Forgot password?</a>',
                listeners: {
                    click: 'forgotPassword'
                }}
            }

Controller:

forgotPassword: function () {
    alert('HHHH');
    this.getView().destroy();
}

But it doesn't work?

Upvotes: 0

Views: 2607

Answers (1)

CD..
CD..

Reputation: 74126

  1. Your listeners shouldn't be in the autoEl object.
  2. Add element: 'el' to your listener.

For example:

{
  xtype: 'component',
  html: '<a href="#">Forgot password?</a>'
  listeners: {
    element: 'el',
    click: 'forgotPassword'
  }
}

https://fiddle.sencha.com/#fiddle/1clt

Upvotes: 4

Related Questions