From 8de69b3173c6bdab5e6a82e8e10c164b190fa5c3 Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Fri, 13 Jan 2012 16:28:01 +0530 Subject: [PATCH] fix a bug in Ox.Input that would make its change event fire more than once --- source/Ox.UI/js/Form/Ox.Input.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/source/Ox.UI/js/Form/Ox.Input.js b/source/Ox.UI/js/Form/Ox.Input.js index bb191680..eb41df4c 100644 --- a/source/Ox.UI/js/Form/Ox.Input.js +++ b/source/Ox.UI/js/Form/Ox.Input.js @@ -596,6 +596,15 @@ Ox.Input = function(options, self) { self.options.placeholder && setPlaceholder(); self.options.validate && validate(); self.bindKeyboard && Ox.UI.$document.unbind('keydown', keydown); + if (!self.cancelled && !self.submitted) { + that.triggerEvent('blur', { + value: self.options.value + }); + self.options.value !== self.originalValue && that.triggerEvent('change', { + value: self.options.value + }); + } + /* self.options.value !== self.originalValue && that.triggerEvent('change', { value: self.options.value }); @@ -604,17 +613,20 @@ Ox.Input = function(options, self) { !self.cancelled && !self.submitted && that.triggerEvent('blur', { value: self.options.value }); + */ } function cancel() { self.cancelled = true; - self.$input.blur().val(self.originalValue); + self.$input.val(self.originalValue).blur(); self.cancelled = false; that.triggerEvent('cancel'); } function change() { + // change gets invoked before blur self.options.value = self.$input.val(); + self.originalValue = self.options.value; that.triggerEvent('change', { value: self.options.value });