From 0c8d1f6089175ee95108d85d1379708094d333bc Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Tue, 16 May 2017 12:05:27 +0200 Subject: [PATCH] [FIX] web: Form: col width of x2many lists inside groups The form renderer defines inline style on the groups it renders to set the width of their children according to the col and colspan attributes specified in the view. However, before this rev., this impacted inner list views (for x2many fields), as their columns get an harcoded width as well, whereas they shouldn't. This was for example the case in the stock.location.route form view, for the push rules and procurement rules o2m fields. --- .../web/static/src/js/views/form/form_renderer.js | 11 ++++++----- addons/web/static/tests/views/form_tests.js | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/addons/web/static/src/js/views/form/form_renderer.js b/addons/web/static/src/js/views/form/form_renderer.js index b4f445cc8eb..a2c0d2129ab 100644 --- a/addons/web/static/src/js/views/form/form_renderer.js +++ b/addons/web/static/src/js/views/form/form_renderer.js @@ -337,11 +337,12 @@ var FormRenderer = BasicRenderer.extend({ $result.append($sep); } + var rows = []; var $currentRow = $(''); var currentColspan = 0; _.each(node.children, function (child) { if (child.tag === 'newline') { - $currentRow.appendTo($result); + rows.push($currentRow); $currentRow = $(''); currentColspan = 0; return; @@ -360,7 +361,7 @@ var FormRenderer = BasicRenderer.extend({ currentColspan += colspan; if (currentColspan > col) { - $currentRow.appendTo($result); + rows.push($currentRow); $currentRow = $(''); currentColspan = colspan; } @@ -378,15 +379,15 @@ var FormRenderer = BasicRenderer.extend({ } $currentRow.append($tds); }); - $currentRow.appendTo($result); + rows.push($currentRow); - _.each($result.find('tr'), function (tr) { - var $tr = $(tr); + _.each(rows, function ($tr) { var nonLabelColSize = 100 / (col - $tr.children('.o_td_label').length); _.each($tr.children(':not(.o_td_label)'), function (el) { var $el = $(el); $el.css('width', ((parseInt($el.attr('colspan'), 10) || 1) * nonLabelColSize) + '%'); }); + $result.append($tr); }); return $result; diff --git a/addons/web/static/tests/views/form_tests.js b/addons/web/static/tests/views/form_tests.js index 6754f9c2eb5..7afb8545934 100644 --- a/addons/web/static/tests/views/form_tests.js +++ b/addons/web/static/tests/views/form_tests.js @@ -4181,7 +4181,7 @@ QUnit.module('Views', { }); QUnit.test('form rendering with groups with col/colspan', function (assert) { - assert.expect(45); + assert.expect(46); var form = createView({ View: FormView, @@ -4210,6 +4210,15 @@ QUnit.module('Views', { '' + '' + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + '' + '', res_id: 1, @@ -4289,6 +4298,10 @@ QUnit.module('Views', { assert.ok($fieldGroupFifthRowTds.eq(1).hasClass('o_td_label'), "the second td should be a label td"); assert.strictEqual($fieldGroupFifthRowTds.eq(2).attr('style').substr(0, 9), "width: 50", "the third td should 50% width"); + // Verify that one2many list table hasn't been impacted + assert.strictEqual(form.$('.o_field_one2many th:first').attr('style'), undefined, + "o2m list columns should have no width harcoded"); + form.destroy(); });