-
26 Nov 2010 7:57 AM #1
[OPEN-1412] Handling specialKey events for TextField (another way)
[OPEN-1412] Handling specialKey events for TextField (another way)
We implement a special number field, which should be usable very comfortable. Due to these proposals we are dependent on a correct specialKey event handling. In the actual Ext version (3.3) there is a different event handling according to which browser you use.
Our investigations point to following:
- Chrome: Sends only keyDown when pressing a special key
- Firefox: Sends keyDown and keyPress when pressing a special key
- InternetExplorer: Send keyDown when pressing a special key
- Opera: Sends keyDown and keyPress when pressing a special key. Sometimes (e.g. '-' on number block) it sends a keyDown event followed by two (yes two!) keyPress events.

We tried to solve this problem that way:
If you - the ExtJs development team - think this is a way, feel free to integrate it.Code:Ext.override(Ext.form.TextField, { keyDownCode:'', onKeyDown:function(e){ var charCode = e.charCode ? e.charCode : e.keyCode; this.keyDownCode = charCode; this.fireEvent('keydown', this, e); if (Ext.isGecko === false && Ext.isOpera === false) { if ((charCode === 8) || (charCode === 9) || (charCode === 13) || (charCode === 127) || (charCode >= 33 && charCode <= 40) || (charCode >= 44 && charCode <= 46)) { this.fireEvent('specialkey', this, e); this.keyDownCode = ''; return; } } }, onKeyPress:function(e){ var charCode = e.charCode ? e.charCode : e.keyCode; if (Ext.isGecko === true || Ext.isOpera === true) { if (charCode === this.keyDownCode) { this.keyDownCode = ''; if (Ext.isOpera === true && e.browserEvent.which > 0) { // Opera sends keys like '-' in the number block as // 'keydown, keypress, keypress' sequence. The first // sequence 'keydown, keypress' has to be ignored. return; } this.fireEvent('specialkey', this, e); return; } } this.fireEvent('keypress', this, e); } });
Best regards,
Dom
-
29 Nov 2010 11:45 PM #2
Oops, I forgot three lines of code:
We have to deactivate the fireKey event.Code:Ext.override(Ext.form.Field, { fireKey:function(e){ } });
-
30 Nov 2010 1:16 AM #3
Sorry for these multiple updates. The actual version:
Code:Ext.override(Ext.form.Field, { fireKey:function(e){ } }); Ext.override(Ext.form.TextField, { keyDownCode:'', isSpecialKey:function(keyCode){ if (this.isSpecialKeyNonPrintable(keyCode) === true) { return true; } return this.isSpecialKeyPrintable(keyCode); }, isSpecialKeyNonPrintable:function(keyCode){ return ((keyCode === 8) || (keyCode === 9) || (keyCode === 13) || (keyCode === 127)); }, isSpecialKeyPrintable:function(keyCode){ return ((keyCode >= 33 && keyCode <= 40) || (keyCode >= 44 && keyCode <= 46)); }, onKeyDown:function(e){ var charCode = e.charCode ? e.charCode : e.keyCode; this.keyDownCode = charCode; this.fireEvent('keydown', this, e); if (Ext.isGecko === false && Ext.isOpera === false) { if (this.isSpecialKey(charCode) === true) { this.fireEvent('specialkey', this, e); this.keyDownCode = ''; return; } } }, onKeyPress:function(e){ var charCode = e.charCode ? e.charCode : e.keyCode; if (Ext.isGecko === true || Ext.isOpera === true) { if ((charCode === this.keyDownCode) && (this.isSpecialKey(charCode) === true)) { this.keyDownCode = ''; if (Ext.isOpera === true && e.browserEvent.which > 0 && this.isSpecialKeyPrintable(charCode) === true) { // Opera sends keys like '-' in the number block as // 'keydown, keypress, keypress' sequence. The first // sequence 'keydown, keypress' has to be ignored. return; } this.fireEvent('specialkey', this, e); return; } } this.fireEvent('keypress', this, e); } });
Thank you for reporting this bug. We will make it our priority to review this report.
Similar Threads
-
TextField not working as expected when using maskRe and specialkey
By sk205 in forum Ext 3.x: Help & DiscussionReplies: 1Last Post: 11 Oct 2010, 3:05 AM -
[OPEN-1094] listening of DataProxy events DirectStore load events fails
By steffen.rahn in forum Ext 3.x: BugsReplies: 6Last Post: 2 Jul 2010, 12:32 AM -
[2.1.1] Popup sends Events.Open not Events.Show contradicting API docs
By janekdb in forum Ext GWT: DiscussionReplies: 0Last Post: 26 Mar 2010, 3:10 AM -
specialkey event not working in a TextField
By jrfuentesh in forum Ext 2.x: Help & DiscussionReplies: 2Last Post: 2 Jul 2009, 6:22 AM -
[2.0a1] TextField and specialkey event concerning backspace key
By rednix in forum Ext 2.x: Help & DiscussionReplies: 0Last Post: 6 Oct 2007, 4:32 PM


Reply With Quote