diff --git a/addons/web/static/src/js/views/kanban/kanban_column_quick_create.js b/addons/web/static/src/js/views/kanban/kanban_column_quick_create.js index 78191d3ab75..afeeb4203ad 100644 --- a/addons/web/static/src/js/views/kanban/kanban_column_quick_create.js +++ b/addons/web/static/src/js/views/kanban/kanban_column_quick_create.js @@ -21,6 +21,8 @@ var ColumnQuickCreate = Widget.extend({ 'click .o_kanban_examples': '_onShowExamples', 'keydown': '_onKeydown', 'keypress input': '_onKeypress', + 'blur input': '_onInputBlur', + 'focus input': '_onInputFocus', }, /** @@ -124,6 +126,27 @@ var ColumnQuickCreate = Widget.extend({ event.stopPropagation(); this._add(); }, + /** + * When the input is not focused, no key event may occur in the column, so + * the discard feature will not work by pressing ESC. We simply hide the + * help message in that case, so we do not mislead our users. + * + * @private + * @param {KeyboardEvent} event + */ + _onInputBlur: function () { + this.$('.o_discard_msg').hide(); + }, + /** + * When the input is focused, we need to show the discard help message (it + * might have been hidden, @see _onInputBlur) + * + * @private + * @param {KeyboardEvent} event + */ + _onInputFocus: function () { + this.$('.o_discard_msg').show(); + }, /** * Cancels quick creation on escape keydown event * diff --git a/addons/web/static/src/xml/kanban.xml b/addons/web/static/src/xml/kanban.xml index d06a39081e5..23af895b8ea 100644 --- a/addons/web/static/src/xml/kanban.xml +++ b/addons/web/static/src/xml/kanban.xml @@ -52,8 +52,9 @@ - See Examples + Examples + Esc to discard
diff --git a/addons/web/static/tests/views/kanban_tests.js b/addons/web/static/tests/views/kanban_tests.js index aa1a9e93e4a..a73eaed2e1a 100644 --- a/addons/web/static/tests/views/kanban_tests.js +++ b/addons/web/static/tests/views/kanban_tests.js @@ -1681,6 +1681,35 @@ QUnit.module('Views', { kanban.destroy(); }); + QUnit.test('hide and display help message (ESC) in kanban quick create', function (assert) { + assert.expect(2); + + var kanban = createView({ + View: KanbanView, + model: 'partner', + data: this.data, + arch: '' + + '' + + '' + + '
' + + '
' + + '
', + groupBy: ['product_id'], + }); + + kanban.$('.o_quick_create_folded').click(); + + assert.ok(kanban.$('.o_discard_msg').is(':visible'), + 'the ESC to discard message is visible'); + + // click in the column, but outside the input (to lose focus) + kanban.$('.o_kanban_header').click(); + assert.notOk(kanban.$('.o_discard_msg').is(':visible'), + 'the ESC to discard message is no longer visible'); + + kanban.destroy(); + }); + QUnit.test('delete a column in grouped on m2o', function (assert) { assert.expect(28);