From a7ad740fa21f662ecf9312d79f97e7bc0c25db7d Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 8 Aug 2012 17:18:43 +0200 Subject: [PATCH] [FIX] ignore blur event on m2o input during autocompletion or if a sub-popup is open jquery.ui.autocomplete does quite a bit of focus-setting during and around itself, leading to blur events being triggered outside expectations (e.g. after an action has been selected and the dropdown has been closed due to the action opening a popup whose content gets focused somehow). Really, the guy who implemented o2m's autosave-on-blur should be shot. Wait, that would be me. bzr revid: xmo@openerp.com-20120808151843-et2r8hplxxyqc7v6 --- addons/web/static/src/js/view_form.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index a73595273b9..357719e1adf 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -2826,7 +2826,21 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(instanc tip_def.reject(); } }; - this.$input.focusout(anyoneLoosesFocus); + var ignore_blur = false; + this.$input.on({ + focusout: anyoneLoosesFocus, + focus: function () { self.trigger('focused'); }, + autocompleteopen: function () { ignore_blur = true; }, + autocompleteclose: function () { ignore_blur = false; }, + blur: function () { + // autocomplete open + if (ignore_blur) { return; } + if (_(self.getChildren()).any(function (child) { + return child instanceof instance.web.form.AbstractFormPopup; + })) { return; } + self.trigger('blurred'); + } + }); var isSelecting = false; // autocomplete @@ -2869,7 +2883,7 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(instanc } isSelecting = false; }); - this.setupFocus(this.$input.add(this.$follow_button)); + this.setupFocus(this.$follow_button); }, render_value: function(no_recurse) { var self = this;