[FIX] web: Form: only render button StatButton

One could want to render something else than a `button` in the
buttonbox (even if the name seems to imply that it will contain
buttons).

In this case, we render the method corresponding to the tag instead
of a button.
This commit is contained in:
Martin Geubelle
2017-04-12 12:23:31 +02:00
parent 3638cade09
commit 16dc001e42
2 changed files with 36 additions and 1 deletions
@@ -251,12 +251,19 @@ return BasicRenderer.extend({
* @returns {jQueryElement}
*/
_renderButtonBox: function (node) {
var self = this;
var $result = $('<' + node.tag + '>', { 'class': 'o_not_full' });
// Avoid to show buttons if we are in create mode (edit mode without res_id)
if (this.mode === 'edit' && !this.state.res_id) {
return $result;
}
var buttons = _.map(node.children, this._renderStatButton.bind(this));
var buttons = _.map(node.children, function (child) {
if (child.tag === 'button') {
return self._renderStatButton(child);
} else {
return self._renderNode(child);
}
});
var buttons_partition = _.partition(buttons, function ($button) {
return $button.is('.o_form_invisible');
});
@@ -2644,6 +2644,34 @@ QUnit.module('Views', {
form.destroy();
});
QUnit.test('diplay something else than a button in a buttonbox', function (assert) {
assert.expect(3);
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<div name="button_box" class="oe_button_box">' +
'<button type="object" class="oe_stat_button" icon="fa-check-square">' +
'<field name="bar"/>' +
'</button>' +
'<label/>' +
'</div>' +
'</form>',
res_id: 2,
});
assert.strictEqual(form.$('.oe_button_box').children().length, 2,
"button box should contain two children");
assert.strictEqual(form.$('.oe_button_box .oe_stat_button').length, 1,
"button box should only contain one button");
assert.strictEqual(form.$('.oe_button_box label').length, 1,
"button box should only contain one label");
form.destroy();
});
QUnit.test('one2many default value creation', function (assert) {
assert.expect(1);