From 3e2cab2aada3a99838736fb7e887c6d43b1719b3 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 15 Jun 2012 07:54:40 +0200 Subject: [PATCH] [FIX] handling of [Return] key to save records being edited in MSIE * DOM events sequence screwed up, requiring an explicit blur on the current target to try and ensure the corresponding form widget would register its own change event * Requirement to stop the default behavior of keypress and keydown on [Return] as they would somehow trigger the contextual menu of m2o fields on the row, at the wrong place, when in a char field (I don't even...) * Delaying of the actual saving of the form (via `setTimeout`) to try and ensure the blur/change event has had the time to propagate correctly (and be handled) before we actually save bzr revid: xmo@openerp.com-20120615055440-yn00uv4q8y29nboq --- .../web/static/src/js/view_list_editable.js | 46 +++++++++++-------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/addons/web/static/src/js/view_list_editable.js b/addons/web/static/src/js/view_list_editable.js index bf4bf205c02..c52bb08536e 100644 --- a/addons/web/static/src/js/view_list_editable.js +++ b/addons/web/static/src/js/view_list_editable.js @@ -168,24 +168,29 @@ openerp.web.list_editable = function (openerp) { var self = this; switch (e.which) { case KEY_RETURN: - this.save_row().then(function (result) { - if (result.created) { - self.new_record(); - return; - } + $(e.target).blur(); + e.preventDefault(); + //e.stopImmediatePropagation(); + setTimeout(function () { + self.save_row().then(function (result) { + if (result.created) { + self.new_record(); + return; + } - var next_record_id, - next_record = self.records.at( - self.records.indexOf(result.edited_record) + 1); - if (next_record) { - next_record_id = next_record.get('id'); - self.dataset.index = _(self.dataset.ids) - .indexOf(next_record_id); - } else { - self.dataset.index = 0; - next_record_id = self.records.at(0).get('id'); - } - self.edit_record(next_record_id); + var next_record_id, + next_record = self.records.at( + self.records.indexOf(result.edited_record) + 1); + if (next_record) { + next_record_id = next_record.get('id'); + self.dataset.index = _(self.dataset.ids) + .indexOf(next_record_id); + } else { + self.dataset.index = 0; + next_record_id = self.records.at(0).get('id'); + } + self.edit_record(next_record_id); + }, 0); }); break; case KEY_ESCAPE: @@ -211,7 +216,12 @@ openerp.web.list_editable = function (openerp) { }) .keyup(function () { return self.on_row_keyup.apply(self, arguments); }) - .keydown(function (e) { e.stopPropagation(); }); + .keydown(function (e) { e.stopPropagation(); }) + .keypress(function (e) { + if (e.which === KEY_RETURN) { + return false; + } + }); if (row) { $new_row.replaceAll(row);