[IMP] web: show clipboard field even if it's empty
**Issue:** When a copy clipboard field is empty, there is no way to edit it because the Field component is not shown. This issue can be reproduced using any type of copy clipboard field: - CopyClipboardChar - CopyClipboardText - CopyClipboardURL Check the following video for illustration: https://youtu.be/CTzqJRtwqv0 **Solution:** This PR proposes a fix of *always* showing the copy clipboard field (together with the copy button) even if the content is empty. For illustration, check: https://youtu.be/jMM7zn_mFCU **Notable changes:** - The modified tests were using a wrong class name. But since they were asserting the "non-existence" of the copy button, they were working. - We are casting null text field to empty string (just like char field) so that we avoid crash (in dev mode) when passing a "boolean" as 'content' props to the 'CopyButton' component. This is asserted in the augmented test case where we also try to render an empty text field. closes odoo/odoo#104248 Task-id: 2861388 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
@@ -448,6 +448,7 @@ export class Record extends DataPoint {
|
||||
: false;
|
||||
break;
|
||||
}
|
||||
case "text":
|
||||
case "char": {
|
||||
data[fieldName] = data[fieldName] || "";
|
||||
break;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<templates xml:space="preserve">
|
||||
|
||||
<t t-name="web.CopyClipboardField" owl="1">
|
||||
<div t-if="props.value" class="d-grid rounded-2 overflow-hidden">
|
||||
<div class="d-grid rounded-2 overflow-hidden">
|
||||
<Field t-props="fieldProps"/>
|
||||
<CopyButton className="copyButtonClassName" content="props.value" copyText="copyText" successText="successText"/>
|
||||
</div>
|
||||
|
||||
@@ -73,8 +73,9 @@ QUnit.module("Fields", (hooks) => {
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("CopyClipboardField on unset field", async function (assert) {
|
||||
QUnit.test("CopyClipboardField: show copy button even on empty field", async function (assert) {
|
||||
serverData.models.partner.records[0].char_field = false;
|
||||
serverData.models.partner.records[0].text_field = false;
|
||||
|
||||
await makeView({
|
||||
serverData,
|
||||
@@ -85,21 +86,25 @@ QUnit.module("Fields", (hooks) => {
|
||||
<sheet>
|
||||
<group>
|
||||
<field name="char_field" widget="CopyClipboardChar" />
|
||||
<field name="text_field" widget="CopyClipboardText" />
|
||||
</group>
|
||||
</sheet>
|
||||
</form>`,
|
||||
resId: 1,
|
||||
});
|
||||
|
||||
assert.containsNone(
|
||||
assert.containsOnce(
|
||||
target,
|
||||
'.o_field_copy[name="char_field"] .o_clipboard_button',
|
||||
"char_field (unset) should not contain a button"
|
||||
'.o_field_CopyClipboardChar[name="char_field"] .o_clipboard_button'
|
||||
);
|
||||
assert.containsOnce(
|
||||
target,
|
||||
'.o_field_CopyClipboardText[name="text_field"] .o_clipboard_button'
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"CopyClipboardField on readonly unset fields in create mode",
|
||||
"CopyClipboardField: show copy button even on readonly empty field",
|
||||
async function (assert) {
|
||||
serverData.models.partner.fields.display_name.readonly = true;
|
||||
|
||||
@@ -117,10 +122,9 @@ QUnit.module("Fields", (hooks) => {
|
||||
</form>`,
|
||||
});
|
||||
|
||||
assert.containsNone(
|
||||
assert.containsOnce(
|
||||
target,
|
||||
'.o_field_copy[name="display_name"] .o_clipboard_button',
|
||||
"the readonly unset field should not contain a button"
|
||||
'.o_field_CopyClipboardChar[name="display_name"] .o_clipboard_button'
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user