Mohamed Ahmed Mohamed Ahmed - 5 months ago 53
Javascript Question

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?

Answer
  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

Comments