[FIX] web: hide CopyClipboard widget button when pointless

The widget has been moved in rev. odoo/odoo@15f3bbe but was not very generic.

In particular, there was a traceback when clicking on the button if the field
had no value (the button was displayed for readonly fields in create mode).

The button is now only appended in readonly mode (a `button` inside an `input`
or a `textarea` is not very DOM friendly) if the field has a value.

Task 1941996

closes odoo/odoo#31635

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Martin Geubelle
2019-03-06 16:11:33 +00:00
parent a3489be331
commit dcf8c67fe3
3 changed files with 88 additions and 58 deletions
@@ -1412,45 +1412,79 @@ QUnit.module('basic_fields', {
list.destroy();
});
QUnit.module('copy_clipboard', {
beforeEach: function () {
this.data = {
partner: {
fields: {
script_external: {string: "Script External", type: "text"},
web_page: {string: "Web page link", type: "char"}
},
records: [{
id: 1,
script_external:'Random Text',
web_page: 'web page links'
},],
},
};
}
});
QUnit.module('CopyClipboard');
QUnit.test('Char & Text Fields: Copy to clipboard button', function (assert) {
assert.expect(2);
var done = assert.async();
testUtils.createAsyncView({
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<sheet>' +
'<div>' +
'<field name="script_external" widget="CopyClipboardText"/>' +
'<field name="web_page" widget="CopyClipboardChar"/>' +
'<field name="txt" widget="CopyClipboardText"/>' +
'<field name="foo" widget="CopyClipboardChar"/>' +
'</div>' +
'</sheet>' +
'</form>',
}).then(function (form) {
assert.strictEqual(form.$('.o_clipboard_button.o_btn_text_copy').length, 1,"Should have copy button on text type field");
assert.strictEqual(form.$('.o_clipboard_button.o_btn_char_copy').length, 1,"Should have copy button on char type field");
form.destroy();
done();
res_id: 1,
});
assert.strictEqual(form.$('.o_clipboard_button.o_btn_text_copy').length, 1,"Should have copy button on text type field");
assert.strictEqual(form.$('.o_clipboard_button.o_btn_char_copy').length, 1,"Should have copy button on char type field");
form.destroy();
});
QUnit.test('CopyClipboard widget on unset field', function (assert) {
assert.expect(1);
this.data.partner.records[0].foo = false;
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<sheet>' +
'<group>' +
'<field name="foo" widget="CopyClipboardChar" />' +
'</group>' +
'</sheet>' +
'</form>',
res_id: 1,
});
assert.containsNone(form, '.o_field_copy[name="foo"] .o_clipboard_button',
"foo (unset) should not contain a button");
form.destroy();
});
QUnit.test('CopyClipboard widget on readonly unset fields in create mode', function (assert) {
assert.expect(1);
this.data.partner.fields.display_name.readonly = true;
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<sheet>' +
'<group>' +
'<field name="display_name" widget="CopyClipboardChar" />' +
'</group>' +
'</sheet>' +
'</form>',
});
assert.containsNone(form, '.o_field_copy[name="display_name"] .o_clipboard_button',
"the readonly unset field should not contain a button");
form.destroy();
});
QUnit.module('FieldText');