From 40a026d5b22047ccfd246d53a42dc1e6b22f225d Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Thu, 11 May 2017 11:06:37 +0200 Subject: [PATCH] [FIX] web: implement form tag behavior Before this commit, the new form view implementation was rendering tags as real DOM element. The wanted behavior is now restored: - As outer group direct child, produce a
tag, forcing the next group children to be on a new line - As inner group direct child, produce nothing but forces the creation of a new (for the next group children) --- .../static/src/js/views/form/form_renderer.js | 12 +++- addons/web/static/tests/views/form_tests.js | 57 +++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) 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 b4576dffa38..6dc4d262022 100644 --- a/addons/web/static/src/js/views/form/form_renderer.js +++ b/addons/web/static/src/js/views/form/form_renderer.js @@ -315,9 +315,16 @@ var FormRenderer = BasicRenderer.extend({ $result.append($sep); } - var currentColspan = 0; var $currentRow = $(''); + var currentColspan = 0; _.each(node.children, function (child) { + if (child.tag === 'newline') { + $currentRow.appendTo($result); + $currentRow = $(''); + currentColspan = 0; + return; + } + var colspan = parseInt(child.attrs.colspan, 10); var isLabeledField = (child.tag === 'field' && child.attrs.nolabel !== '1'); if (!colspan) { @@ -524,6 +531,9 @@ var FormRenderer = BasicRenderer.extend({ var $result = $('
', {class: 'o_group'}); var colSize = Math.max(1, Math.round(12 / (parseInt(node.attrs.col, 10) || 2))); $result.append(_.map(node.children, function (child) { + if (child.tag === 'newline') { + return $('
'); + } var $child = self._renderNode(child); $child.addClass('o_group_col_' + (colSize * (parseInt(child.attrs.colspan, 10) || 1))); return $child; diff --git a/addons/web/static/tests/views/form_tests.js b/addons/web/static/tests/views/form_tests.js index 3d4401be073..2d7cda2bf8c 100644 --- a/addons/web/static/tests/views/form_tests.js +++ b/addons/web/static/tests/views/form_tests.js @@ -4257,5 +4257,62 @@ QUnit.module('Views', { form.destroy(); }); + + QUnit.test('form group with newline tag inside', function (assert) { + assert.expect(6); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: + '
' + + '' + + '' + + // col=5 otherwise the test is ok even without the + // newline code as this will render a DOM + // element in the third column, leaving no place for + // the next field and its label on the same line. + '' + + '' + + '' + + '' + + '' + + '' + + // col=3 otherwise the test is ok even without the + // newline code as this will render a DOM + // element with the o_group_col_6 class, leaving no + // place for the next group on the same line. + '' + + '
' + + '' + + '' + + '' + + '
' + + '' + + '' + + '' + + '', + res_id: 1, + }); + + // Inner group + assert.strictEqual(form.$('.main_inner_group > tbody > tr').length, 2, + "there should be 2 rows in the group"); + assert.strictEqual(form.$('.main_inner_group > tbody > tr:first > .o_td_label').length, 1, + "there should be only one label in the first row"); + assert.strictEqual(form.$('.main_inner_group > tbody > tr:first .o_field_widget').length, 1, + "there should be only one widget in the first row"); + assert.strictEqual(form.$('.main_inner_group > tbody > tr:last > .o_td_label').length, 2, + "there should be two labels in the second row"); + assert.strictEqual(form.$('.main_inner_group > tbody > tr:last .o_field_widget').length, 2, + "there should be two widgets in the second row"); + + // Outer group + assert.ok((form.$('.bottom_group').position().top - form.$('.top_group').position().top) >= 200, + "outergroup children should not be on the same line"); + + form.destroy(); + }); }); });