PDA

View Full Version : KeyMap doesn't act on defaultEventAction but performs the default browser action



nil5286
13 Aug 2012, 4:00 AM
Using ExtJS 4.1.1 even though in Ext.util.KeyMap i have set the defaultEventAction: 'preventDefault' and in the fn : function also i have set the e.preventDefault(); still it opens the new tab in chrome? I just want the field to perform the action fn the keys are implemented for and not the default browser action of opening the new tab. How is this possible?


Ext.onReady(function () {

var bcTextField = Ext.create('Ext.form.Text', {
xtype: 'textfield',
renderTo: 'console-output',
emptyText: 'Enter Barcode/Accession Number',
width: 200,
margin: '0'
});
var map = new Ext.util.KeyMap({
target: bcTextField.getEl(),
binding: [{
key: "t",
ctrl: true,
scope: this,
defaultEventAction: 'preventDefault',
fn: function (key, e) {
e.preventDefault();
alert('Ctrl + t was pressed.');
}
}]
});
});

Any kind of help is appreciated.

kaiden.vo
13 Aug 2012, 2:58 PM
What you're doing is correct. Just remove the alert().