[IMP] web: improve renderCheckbox to be re-usable in front end

Before this commit, the label was into a display block that add a return line
between the cehckbox and the label.

It was not visible in backend, because label by defaut is displayed without
renderCheckbox. (no options.text provided)

Now renderCheckbox render correctly with the same code in frontend and backend
This commit is contained in:
rde
2017-09-25 10:53:28 +02:00
committed by Jeremy Kersten
parent a40236d38a
commit b94939377a
3 changed files with 20 additions and 11 deletions
+5 -5
View File
@@ -265,19 +265,19 @@ return {
* @returns {jQuery}
*/
renderCheckbox: function (options) {
var $container = $('<div class="o_checkbox"><input type="checkbox"/><span/></div>');
var $container = $('<div class="checkbox o_checkbox"><label><input type="checkbox"/><span/></label></div>');
if (options && options.prop) {
$container.children('input').prop(options.prop);
$container.find('input').prop(options.prop);
}
if (options && options.text) {
$container = $('<label/>').append(
$container,
$container.find('label').append(
$('<span/>', {
class: 'ml8',
text: options.text,
class: 'o_checkbox_label',
})
);
}
return $container;
},
/**
@@ -4,8 +4,17 @@
div.o_checkbox {
display: inline-block;
vertical-align: sub;
> input + span {
display: none;
margin-top: 0px;
margin-bottom: 0px;
input[type="checkbox"] {
position: inherit;
margin-left: 0;
}
> label {
padding-left: 0px;
> input + span {
display: none;
}
}
}
+4 -4
View File
@@ -1741,10 +1741,10 @@ QUnit.module('Views', {
res_id: 1,
});
assert.strictEqual(form.$("label").length, 2, "should have rendered only two label");
assert.strictEqual(form.$("label").first().text(), "Product",
assert.strictEqual(form.$("label:not(.o_checkbox label)").length, 2, "should have rendered only two label");
assert.strictEqual(form.$("label:not(.o_checkbox label)").first().text(), "Product",
"one should be the one for the product field");
assert.strictEqual(form.$("label").eq(1).text(), "Bar",
assert.strictEqual(form.$("label:not(.o_checkbox label)").eq(1).text(), "Bar",
"one should be the one for the bar field");
assert.strictEqual(form.$('.firstgroup td').first().attr('colspan'), undefined,
@@ -3787,7 +3787,7 @@ QUnit.module('Views', {
"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,
assert.strictEqual(form.$('.oe_button_box label:not(.o_checkbox label)').length, 1,
"button box should only contain one label");
form.destroy();