1 include(bbq.gui.form.FormField); 2 3 bbq.gui.form.TextField = new Class.create(bbq.gui.form.FormField, /** @lends bbq.gui.form.TextField.prototype */ { 4 _onKeyPressValue: null, 5 _onKeyPressTimeOut: null, 6 7 /** 8 * @constructs 9 * @extends bbq.gui.form.FormField 10 */ 11 initialize: function($super, options) { 12 try { 13 $super(options); 14 15 this.addClass("TextField"); 16 17 this.getRootNode().type = "text"; 18 this.getRootNode().onkeydown = this._keyDown.bind(this); 19 this.getRootNode().onkeyup = this._keyUp.bind(this); 20 } catch(e) { 21 Log.error("Error constructing TextField", e); 22 } 23 }, 24 25 _keyDown: function() { 26 this._onKeyPressValue = this.getRootNode().value; 27 }, 28 29 _keyUp: function() { 30 if(this._onKeyPressValue != this.getRootNode().value) { 31 // if the timeout already exists, cancel it so only one is dispatched 32 if(this._onKeyPressTimeOut) { 33 clearTimeout(this._onKeyPressTimeOut); 34 } 35 36 // Set a timeout so we only dispatch the event after editing has finished 37 this._onKeyPressTimeOut = setTimeout(this.notifyListeners.bind(this, "onChange"), 500); 38 } 39 } 40 }); 41