From 178873d4337148e75041c61c9cd1862edaafa37d Mon Sep 17 00:00:00 2001 From: Khoi Nguyen Date: Mon, 14 Aug 2017 14:53:44 +0200 Subject: [FIX] web: fix copy (Ctrl-C) of text field content in Firefox Before this commit, it was not possible to copy the contents of a multiline text field in read-only mode in Firefox without losing all line breaks in the process. This is due to a bug affecting div tags (see https://bugzilla.mozilla.org/show_bug.cgi?id=1390115) in Firefox. This commit ensures that the text in a text field is surrounded by a span (as opposed to div) tag. Note that spans were used in saas-15, so we are in fact simply undoing the change to divs introduced by the new views. --- .../web/static/tests/fields/basic_fields_tests.js | 33 +++++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'addons/web/static/tests/fields/basic_fields_tests.js') diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index 8f1c04b6bb8..0be9bed3fa9 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -1054,8 +1054,8 @@ QUnit.module('basic_fields', { res_id: 1, }); - assert.ok(form.$('div.o_field_text').length, "should have a text area"); - assert.strictEqual(form.$('div.o_field_text').text(), 'yop', 'should be "yop" in readonly'); + assert.ok(form.$('.o_field_text').length, "should have a text area"); + assert.strictEqual(form.$('.o_field_text').text(), 'yop', 'should be "yop" in readonly'); form.$buttons.find('.o_form_button_edit').click(); @@ -1071,7 +1071,7 @@ QUnit.module('basic_fields', { form.$buttons.find('.o_form_button_save').click(); - assert.strictEqual(form.$('div.o_field_text').text(), 'hello world', + assert.strictEqual(form.$('.o_field_text').text(), 'hello world', 'should be "hello world" after save'); form.destroy(); }); @@ -1091,7 +1091,7 @@ QUnit.module('basic_fields', { res_id: 1, }); - var $field = form.$('div.o_field_text'); + var $field = form.$('.o_field_text'); assert.strictEqual($field.outerHeight(), $field[0].scrollHeight, "text field should not have a scroll bar"); @@ -1193,6 +1193,31 @@ QUnit.module('basic_fields', { list.destroy(); }); + // Firefox-specific + // Copying from
does not keep line breaks + // See https://bugzilla.mozilla.org/show_bug.cgi?id=1390115 + QUnit.test('copying text fields in RO mode should preserve line breaks', function (assert) { + assert.expect(1); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '
' + + '' + + '' + + '' + + '' + + '' + + '
', + res_id: 1, + }); + + // Copying from a div tag with white-space:pre-wrap doesn't work in Firefox + assert.strictEqual(form.$('[name="txt"]').prop("tagName").toLowerCase(), 'span', + "the field contents should be surrounded by a span tag"); + }); + QUnit.module('FieldBinary'); QUnit.test('binary fields are correctly rendered', function (assert) { -- cgit v1.2.3