[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.
This commit is contained in:
Aaron Bohy
2017-05-16 14:07:49 +02:00
parent b0e51ffade
commit 0c8d1f6089
2 changed files with 20 additions and 6 deletions
@@ -337,11 +337,12 @@ var FormRenderer = BasicRenderer.extend({
$result.append($sep);
}
var rows = [];
var $currentRow = $('<tr/>');
var currentColspan = 0;
_.each(node.children, function (child) {
if (child.tag === 'newline') {
$currentRow.appendTo($result);
rows.push($currentRow);
$currentRow = $('<tr/>');
currentColspan = 0;
return;
@@ -360,7 +361,7 @@ var FormRenderer = BasicRenderer.extend({
currentColspan += colspan;
if (currentColspan > col) {
$currentRow.appendTo($result);
rows.push($currentRow);
$currentRow = $('<tr/>');
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;
+14 -1
View File
@@ -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', {
'</group>' +
'</group>' +
'</group>' +
'<group>' +
'<field name="p">' +
'<tree>' +
'<field name="display_name"/>' +
'<field name="foo"/>' +
'<field name="int_field"/>' +
'</tree>' +
'</field>' +
'</group>' +
'</sheet>' +
'</form>',
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();
});