From ff19bed2b30015fdbe82e2dca4cf951afacd375f Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 8 Jul 2011 14:38:53 +0200 Subject: [PATCH] [FIX] the keyup event using the return key on a selection widget should not propagate if that [Return] press changed the widget's value bzr revid: xmo@openerp.com-20110708123853-znak06wgm4uvoi7q --- addons/base/static/src/js/form.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/addons/base/static/src/js/form.js b/addons/base/static/src/js/form.js index 2624759dece..7517ec23e01 100644 --- a/addons/base/static/src/js/form.js +++ b/addons/base/static/src/js/form.js @@ -1121,8 +1121,28 @@ openerp.base.form.FieldSelection = openerp.base.form.Field.extend({ }); }, start: function() { + // Flag indicating whether we're in an event chain containing a change + // event on the select, in order to know what to do on keyup[RETURN]: + // * If the user presses [RETURN] as part of changing the value of a + // selection, we should just let the value change and not let the + // event broadcast further (e.g. to validating the current state of + // the form in editable list view, which would lead to saving the + // current row or switching to the next one) + // * If the user presses [RETURN] with a select closed (side-effect: + // also if the user opened the select and pressed [RETURN] without + // changing the selected value), takes the action as validating the + // row + var ischanging = false; this._super.apply(this, arguments); - this.$element.find('select').change(this.on_ui_change); + this.$element.find('select') + .change(this.on_ui_change) + .change(function () { ischanging = true; }) + .click(function () { ischanging = false; }) + .keyup(function (e) { + if (e.which !== 13 || !ischanging) { return; } + e.stopPropagation(); + ischanging = false; + }); }, set_value: function(value) { value = value === null ? false : value;