From 6595e770f0c4d4c7db6293f5276898d0d19f2a47 Mon Sep 17 00:00:00 2001 From: "Nasreddin (bon)" Date: Tue, 12 Jan 2021 12:13:41 +0000 Subject: [PATCH] [FIX] web: Not hide daterange if scrolling on mobile + unit test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue - Install "Field Service" app - Create new task - Try to select Planned start/end date and valid Daterange picker is hiding when trying to scroll down to valid selection. Cause The daterange picker is closed when ev.target is not inside the picker, however ev.target always return the document element. Solution Do not hide daterange picker on scrolling if on mobile. Note : It will only apply if scrolling on the daterange picker and will still hide if scrolling outside this last one. opw-2428099 closes odoo/odoo#65435 X-original-commit: 1d9b6f56e70faee13cda0ccb9893ed49904ab319 Signed-off-by: Adrien Dieudonné (adr) --- .../web/static/src/js/fields/basic_fields.js | 2 +- .../tests/fields/basic_fields_mobile_tests.js | 49 +++++++++++++++++++ 2 files changed, 50 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 0844030833f..2f20b3cde46 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -802,7 +802,7 @@ var FieldDateRange = InputField.extend({ */ _onDateRangePickerShow() { this._onScroll = ev => { - if (!this.$pickerContainer.get(0).contains(ev.target)) { + if (!config.device.isMobile && !this.$pickerContainer.get(0).contains(ev.target)) { this.$el.data('daterangepicker').hide(); } }; diff --git a/addons/web/static/tests/fields/basic_fields_mobile_tests.js b/addons/web/static/tests/fields/basic_fields_mobile_tests.js index d4657a65856..4b8b435378d 100644 --- a/addons/web/static/tests/fields/basic_fields_mobile_tests.js +++ b/addons/web/static/tests/fields/basic_fields_mobile_tests.js @@ -173,6 +173,55 @@ QUnit.module('basic_fields', { form.destroy(); }); + + QUnit.module('FieldDateRange'); + + QUnit.test('date field: toggle daterangepicker then scroll', async function (assert) { + assert.expect(4); + const scrollEvent = new UIEvent('scroll'); + + function scrollAtHeight(height) { + window.scrollTo(0, height); + document.dispatchEvent(scrollEvent); + } + this.data.partner.fields.date_end = {string: 'Date End', type: 'date'}; + + var form = await createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '
' + + '' + + '' + + '', + session: { + getTZOffset: function () { + return 330; + }, + }, + }); + + // Check date range picker initialization + assert.containsN(document.body, '.daterangepicker', 2, + "should initialize 2 date range picker"); + + // Open date range picker + await testUtils.dom.click("input[name=date]"); + assert.isVisible($('.daterangepicker:first'), + "date range picker should be opened"); + + // Scroll + scrollAtHeight(50); + assert.isVisible($('.daterangepicker:first'), + "date range picker should be opened"); + + // Close picker + await testUtils.dom.click($('.daterangepicker:first .cancelBtn')); + assert.isNotVisible($('.daterangepicker:first'), + "date range picker should be closed"); + + form.destroy(); + }); }); }); });