PDA

View Full Version : determining dot/delete key in event



hicker
27 Mar 2007, 12:07 AM
hi i'm trying to set NumberField's decimalSeperator to ",". but in firefox dot is always allowed by the NumberField because of e.getKey is 46 for delete key and dot key. i've looked to EventManager.js for getKey method:

getKey : function(){
var k = this.keyCode || this.charCode;
return Ext.isSafari ? (safariKeys[k] || k) : k;
}
for delete: this.keyCode = 46, this.charCode = 0
for dot: this.keyCode = 0, this.charCode = 46
so for both getKey=46...
and second problem is NumberField accepts decimal separator for multiple times.
i solved these problems changing keypress event handler function for NumberField in NumberField.initEvents:

var keyPress = function(e){
var allowed = "0123456789";
if(this.allowDecimals && this.el.dom.value.indexOf(this.decimalSeparator)<0){
allowed += this.decimalSeparator;
}
if(this.allowNegative && this.el.dom.value.indexOf("-")<0){
allowed += "-";
}
var k = e.getKey();
if(!Ext.isIE && e.charCode==0 && (e.isNavKeyPress() || k == e.BACKSPACE || k == e.DELETE)){
return;
}
var c = e.getCharCode();
if(allowed.indexOf(String.fromCharCode(c)) === -1){
e.stopEvent();
}
};
i hope this or another solve for this problem will be in further revisions