3

I have the simple form:

   myForm = new Ext.form.FormPanel({
      width:'100%',
      frame:false,
      items: [
         new Ext.form.TextArea({
            id:'notes',
  name: 'notes',
  hideLabel: true,
            width:350,
            height:200
         })
      ],
      buttons: [
         {
    text:"Save",
    click: function (b,e) {
     alert('x');
    }
  }
      ]
   });

However I am having trouble getting the click event of the button to work. Do buttons created the following way have the same functionality of doing Ext.Button?

roobotta
  • 37
  • 2
  • 3
  • 7

1 Answers1

7

You either need

a) The handler option (a click shortcut)

new Ext.Button({
    handler: function(){ 
        // ....
    }
});

b) Event listeners need to be registered in in a listeners block, so

new Ext.Button({
    listeners: {
        click: function(){
            // ...
        }
    }
});

A) is preferred.

Evan Trimboli
  • 29,900
  • 6
  • 45
  • 66
  • Yeah I ended up having to use a Ext.Button, I just thought it was a bit better practice to make use of the buttons section! – roobotta Jun 25 '10 at 15:37
  • You can add the handler config to a button config in your buttons array -- you do not have to create an Ext.Button() object to do that. – Brian Moeskau Jun 25 '10 at 18:37