diff --git a/etemplate/js/et2_widget_number.js b/etemplate/js/et2_widget_number.js index cc3c48c850..42bcd41cc9 100644 --- a/etemplate/js/et2_widget_number.js +++ b/etemplate/js/et2_widget_number.js @@ -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]); }, diff --git a/etemplate/js/et2_widget_textbox.js b/etemplate/js/et2_widget_textbox.js index 2704c4e883..b08c83d209 100644 --- a/etemplate/js/et2_widget_textbox.js +++ b/etemplate/js/et2_widget_textbox.js @@ -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()