Skip to content

Commit

Permalink
[FIX] web: fix form view "More" button
Browse files Browse the repository at this point in the history
In form views, when the window size is too small, a "More" button
appears and it should contain the overflow buttons.

On all browsers, the "More" dropdown doesn't contain the expected
amount of buttons, so it is shifted on the second line.

Before this commit:

    - The "More" dropdown doesn't contain the expected amount of
      buttons, so it is shifted on the second line.

After this commit:

    - The "More" dropdown contains the expected amount of buttons
      and it is not shifted on the second line anymore.

OPW-2079694

X-original-commit: f04f67e
  • Loading branch information
fw-bot committed Oct 25, 2019
1 parent 8cac60b commit 2bda823
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion addons/web/static/src/js/views/form/form_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ var FormRenderer = BasicRenderer.extend({
* @returns {integer}
*/
_renderButtonBoxNbButtons: function () {
return [2, 2, 4, 6][config.device.size_class] || 7;
return [2, 2, 2, 4][config.device.size_class] || 7;
},
/**
* @private
Expand Down
43 changes: 43 additions & 0 deletions addons/web/static/tests/views/form_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -5091,6 +5091,49 @@ QUnit.module('Views', {
form.destroy();
});

QUnit.test('correct amount of buttons', async function (assert) {
assert.expect(7);

var self = this;
var buttons = Array(8).join(
'<button type="object" class="oe_stat_button" icon="fa-check-square">' +
'<field name="bar"/>' +
'</button>'
);
var statButtonSelector = '.oe_stat_button:not(.dropdown-item, .dropdown-toggle)';

var createFormWithDeviceSizeClass = async function (size_class) {
return await createView({
View: FormView,
model: 'partner',
data: self.data,
arch: '<form>' +
'<div name="button_box" class="oe_button_box">'
+ buttons +
'</div>' +
'</form>',
res_id: 2,
config: {
device: {size_class: size_class},
},
});
}

var assertFormContainsNButtonsWithSizeClass = async function (size_class, n) {
var form = await createFormWithDeviceSizeClass(size_class);
assert.containsN(form, statButtonSelector, n, 'The form has the expected amount of buttons');
form.destroy();
}

await assertFormContainsNButtonsWithSizeClass(0, 2);
await assertFormContainsNButtonsWithSizeClass(1, 2);
await assertFormContainsNButtonsWithSizeClass(2, 2);
await assertFormContainsNButtonsWithSizeClass(3, 4);
await assertFormContainsNButtonsWithSizeClass(4, 7);
await assertFormContainsNButtonsWithSizeClass(5, 7);
await assertFormContainsNButtonsWithSizeClass(6, 7);
});

QUnit.module('focus and scroll test', async function () {
QUnit.test('no focus set on form when closing many2one modal if lastActivatedFieldIndex is not set', async function (assert) {
assert.expect(8);
Expand Down

0 comments on commit 2bda823

Please sign in to comment.