PDA

View Full Version : Focus on a textfield when any key is pressed



Obiz
9 Jan 2011, 11:42 AM
Hello world !

I'm starting with extjs (helped by the exellent book "Learning Ext Js"), and I'm not experienced enouth to find a solution:

I need to use a barcodes scanner to make searches on database records; but, for now, I need to select the search field (a simple textfield) with the mouse before I can scan my barcode.

I would like the textfield to be automatically focused and selected when I scan.

Anyone have a solution ?

Thanks a lot

PS: important information for those who never used a barcode scanner: it acts like a keyboard; when you scan a barcode, it's exactely the same if you type the barcode number on your keyboard and you hit Enter.

MrSparks
9 Jan 2011, 2:47 PM
PS: important information for those who never used a barcode scanner: it acts like a keyboard; when you scan a barcode, it's exactely the same if you type the barcode number on your keyboard and you hit Enter.

I use the following to capture an "Enter" key press and automatically click the submit button. If the barcode is as you say acting like a keyboard, maybe you could find the key map id and adapt this code.



keys: [{ key: [10, 13], fn: function() {
var bt = Ext.getCmp('mySubmitButton');
bt.focus();
bt.fireEvent("click", bt);
}
}],
Alternatively, you could just use mytextfield.focus();

Obiz
10 Jan 2011, 2:44 AM
Thank you MrSparks for your reply. I'll try your method.