onkeypress handler for textbox and number widget

This commit is contained in:
Ralf Becker 2015-03-19 21:21:03 +00:00
parent 62019e52eb
commit 21aa3eb325
2 changed files with 29 additions and 1 deletions

View File

@ -94,7 +94,14 @@ var et2_number = et2_textbox.extend(
this.input.addClass("et2_textbox");
// bind invalid event to change, to trigger our validation
this.input.on('invalid', jQuery.proxy(this.change, this));
if (this.options.onkeypress && typeof this.options.onkeypress == 'function')
{
var self = this;
this.input.keypress(function(_ev)
{
return self.options.onkeypress.call(this, _ev, self);
});
}
this.setDOMNode(this.input[0]);
},

View File

@ -74,6 +74,12 @@ var et2_textbox = et2_inputWidget.extend([et2_IResizeable],
"type": "string",
"default": "",
"description": "Weither or not browser should autocomplete that field: 'on', 'off', 'default' (use attribute from form)"
},
onkeypress: {
name: "onKeypress",
type: "js",
default: et2_no_init,
description: "JS code or app.$app.$method called when key is pressed, return false cancels it."
}
},
@ -137,6 +143,21 @@ var et2_textbox = et2_inputWidget.extend([et2_IResizeable],
{
this.set_value(this.options.value);
}
if (this.options.onkeypress && typeof this.options.onkeypress == 'function')
{
var self = this;
this.input.keypress(function(_ev)
{
return self.options.onkeypress.call(this, _ev, self);
});
}
},
destroy: function() {
var node = this.getInputNode();
if (node) $j(node).unbind("keypress");
this._super.apply(this, arguments);
},
getValue: function()