-
10 May 2009 3:49 PM #1
[RESOLVED]KeyPress -- Need to return false when CAPSLOCK active
[RESOLVED]KeyPress -- Need to return false when CAPSLOCK active
this return false dont stop a writeCode:keypress: function(e) { var charCode = e.getCharCode(); if( (e.shiftKey && charCode >= 97 && charCode <= 122) || (!e.shiftKey && charCode >= 65 && charCode <= 90) ){ if (this.showCapsWarning) { this.showWarning(e.target); } return false; } else { this.hideWarning(); } },
-
10 May 2009 9:44 PM #2Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 40
Try:
Code:e.stopEvent();
-
11 May 2009 4:58 AM #3
-
11 May 2009 5:23 AM #4Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 40
On which browser?
ps. For IE you sometimes have to add:
Code:if(Ext.isIE) {e.browserEvent.keyCode = 0;}
-
11 May 2009 5:48 AM #5
Condor this
and thisCode:e.stopEvent();
work !Code:if(Ext.isIE) {e.browserEvent.keyCode = 0;}
Need to verify if user press SHIFT, how ?
-
11 May 2009 5:54 AM #6Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 40
It works on my Firefox...
Code:var t = new Ext.form.TextField({ enableKeyEvents: true, listeners: { keypress: function(f, e){ var charCode = e.charCode; if((e.shiftKey && charCode >= 97 && charCode <= 122) || (!e.shiftKey && charCode >= 65 && charCode <= 90)){ e.stopEvent(); } } } });
-
11 May 2009 6:15 AM #7
is here dont work with SHIFT and work with CAPSLOCK
Code:new Ext.form.TextField({ enableKeyEvents: true, listeners: { keypress: function(f, e){ var charCode = e.charCode; if((e.shiftKey && charCode >= 97 && charCode <= 122) || (!e.shiftKey && charCode >= 65 && charCode <= 90)){ e.stopEvent(); } } } });
-
11 May 2009 6:22 AM #8Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 40
I don't understand... Which keys do you want to block?
- Normal keys
- Shifted keys
- Normal keys with Caps-Lock
- Shifted keys with Caps-Lock
-
11 May 2009 6:43 AM #9
-
11 May 2009 6:53 AM #10Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 40
So you don't want to block Caps-Lock at all! You want to block uppercase!
Try:
which can be simplified to:Code:var t = new Ext.form.TextField({ enableKeyEvents: true, listeners: { keypress: function(f, e){ var charCode = e.charCode; if(charCode >= 65 && charCode <= 90){ e.stopEvent(); } } } });
Or, to also handle pasted uppercase text:Code:var t = new Ext.form.TextField({ maskRe: /[^A-Z]/ });
Code:var t = new Ext.form.TextField({ maskRe: /[^A-Z]/, processValue: function(value){ value = this.constructor.prototype.processValue.call(this, value); var newValue = value.toLowerCase(); if(newValue !== value){ this.setRawValue(newValue); return newValue; } return value; } });


Reply With Quote