From 73a1e7f60ef48ee697ee9cb7d79405a4e56b3e2f Mon Sep 17 00:00:00 2001 From: Hardik Prajapati Date: Thu, 30 Apr 2020 13:22:01 +0000 Subject: [PATCH] [FIX] web: select date/datetime value when tabbing in before this commit, tabbing into the date or datetime field input it has only focus, value is not selected. after this commit, navigate through a view in edit mode with the TAB key, when focus comes into date/dateetime field input then input is focused and value of date/datetime field is also get selected. task-2246593 closes odoo/odoo#51062 X-original-commit: 962e4e18b559d90aa3456c77035659ac8017501d Signed-off-by: Aaron Bohy (aab) Co-authored-by: Mohammed Shekha --- .../web/static/src/js/fields/basic_fields.js | 2 +- addons/web/static/tests/views/form_tests.js | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index f5f59235a0c..bf225d7ea99 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -773,7 +773,7 @@ var FieldDate = InputField.extend({ */ activate: function () { if (this.isFocusable() && this.datewidget) { - this.datewidget.focus(); + this.datewidget.$input.select(); return true; } return false; diff --git a/addons/web/static/tests/views/form_tests.js b/addons/web/static/tests/views/form_tests.js index 77df0909de4..3427244881b 100644 --- a/addons/web/static/tests/views/form_tests.js +++ b/addons/web/static/tests/views/form_tests.js @@ -4472,6 +4472,52 @@ QUnit.module('Views', { form.destroy(); }); + QUnit.test('navigation with tab key selects a value in form view', async function (assert) { + assert.expect(5); + + const form = await createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: ` +
+ + + + + + + `, + res_id: 1, + viewOptions: { + mode: 'edit', + }, + }); + + await testUtils.dom.click(form.el.querySelector('input[name="display_name"]')); + await testUtils.fields.triggerKeydown(document.activeElement, 'tab'); + assert.strictEqual(document.getSelection().toString(), "10", + "int_field value should be selected"); + + await testUtils.fields.triggerKeydown(document.activeElement, 'tab'); + assert.strictEqual(document.getSelection().toString(), "0.4", + "qux field value should be selected"); + + await testUtils.fields.triggerKeydown(document.activeElement, 'tab'); + assert.strictEqual(document.getSelection().toString(), "aaa", + "trululu field value should be selected"); + + await testUtils.fields.triggerKeydown(document.activeElement, 'tab'); + assert.strictEqual(document.getSelection().toString(), "01/25/2017", + "date field value should be selected"); + + await testUtils.fields.triggerKeydown(document.activeElement, 'tab'); + assert.strictEqual(document.getSelection().toString(), "12/12/2016 10:55:05", + "datetime field value should be selected"); + + form.destroy(); + }); + QUnit.test('clicking on a stat button with a context', async function (assert) { assert.expect(1);