PDA

View Full Version : Prevent default button action for HTML button



DavidSSL
25 Aug 2011, 6:27 AM
I would like to know how to prevent the default action for an HTML button click event.
My code is as follows:


Ext.get('copyShippingToBilling').on('click', function () {
// Do something
// Prevent/cancel click event
});


I debugged the event handler, and I saw that the Ext.get('copyShippingToBilling') was returning Ext.util.Animate which doesn't have a preventDefault() method.

So my questions are:

Why am I getting an Ext.util.Animate returned? I was expecting a Ext.button.Button to be returned.
How do I prevent the default behaviour of the button click?

arthurakay
25 Aug 2011, 7:11 AM
Ext.get() returns an Ext.Element(). Your button is an HTML DOM element, so it will never reference anything related to an ExtJS button component. Very different things.

look at the API docs for the "click" event on Ext.Element. The first argument is the event object you want... it should have the preventDefault() method.