Hello,
I have tried the following in order to prevent for unwanted usage of backspace, but the page ignores the “return false” and leaves my form anyhow:
dhtmlxCombo__frm_fsmAfCountries.attachEvent("onKeyPressed", function(keyCode){
if (keyCode == 8) {
if(confirm('Do you really want to leave this page?')) { return true; } else { return false; }
}
});
Any suggestions?
Hello,
onKeyPressed event doesn’t return any value. You may try to redefine the private _onKey event handler to solve the problem:
[code]var setter = dhtmlXCombo.prototype._onKey;
dhtmlXCombo.prototype._onKey = function(e){
var combo=this.parentNode.combo;
(e||event).cancelBubble=true;
var keyCode=(e||event).keyCode;
if(keyCode==8&&combo.getComboText()=="")
return false
return setter.apply(this,arguments);
}[/code]
var setter = dhtmlXCombo.prototype._onKey;
dhtmlXCombo.prototype._onKey = function(e){
var combo=this.parentNode.combo;
(e||event).cancelBubble=true;
var keyCode=(e||event).keyCode;
if (keyCode==8&&combo.getComboText()=="") {
alert(Abort');
}
else {
alert('Continue');
// return setter.apply(this,arguments);
}
}
Does not work. I never get any alerts from function…
locally the same approach works. I’ve attached the demo
sample.zip (17.5 KB)