[FIX] web: add a Go to URL button to UrlField in edition

This commit adds a Go to Url button next to the UrlField input. Since form
views are always set in edition mode, it was no longer possible to open
URLs by clicking on the link. Now, a button has been added directly after
the input to bring back the original feature.

Tests assert the right behavior regarding this button.

X-original-commit: e97215e78500a7b36aa0da073c767f5f96198d3f
Part-of: odoo/odoo#101786
This commit is contained in:
luvi
2022-09-30 18:42:31 +02:00
parent aea8a49a35
commit e8a9868605
4 changed files with 36 additions and 9 deletions
@@ -19,7 +19,7 @@
</t>
<t t-name="web.FormPhoneField" t-inherit="web.PhoneField" t-inherit-mode="primary">
<xpath expr="//div[hasclass('o_phone_content')]//input" position="after">
<xpath expr="//input" position="after">
<a
t-if="props.value"
t-att-href="'tel:'+props.value"
@@ -45,4 +45,8 @@ UrlField.extractProps = ({ attrs }) => {
};
};
class FormUrlField extends UrlField {}
FormUrlField.template = "web.FormUrlField";
registry.category("fields").add("url", UrlField);
registry.category("fields").add("form.url", FormUrlField);
@@ -6,15 +6,30 @@
<a class="o_field_widget o_form_uri" t-on-click.stop="" t-att-href="formattedHref" t-esc="props.text || props.value || ''" target="_blank"/>
</t>
<t t-else="">
<input
class="o_input"
t-att-id="props.id"
type="text"
t-att-placeholder="props.placeholder"
t-att-required="props.required"
t-ref="input"
/>
<div class="d-inline-flex w-100">
<input
class="o_input"
t-att-id="props.id"
type="text"
t-att-placeholder="props.placeholder"
t-att-required="props.required"
t-ref="input"
/>
</div>
</t>
</t>
<t t-name="web.FormUrlField" t-inherit="web.UrlField" t-inherit-mode="primary">
<xpath expr="//input" position="after">
<a
t-if="props.value"
t-att-href="formattedHref"
class="ms-3 d-inline-flex align-items-center"
target="_blank"
>
<i class="fa fa-globe" data-tooltip="Go to URL" aria-label="Go to URL"></i>
</a>
</xpath>
</t>
</templates>
@@ -63,6 +63,14 @@ QUnit.module("Fields", (hooks) => {
"input should contain field value"
);
const webLink = target.querySelector(".o_field_url a");
assert.containsOnce(
target,
webLink,
"should have rendered the url button as a link with correct classes"
);
assert.hasAttrValue(webLink, "href", "http://yop", "should have proper href");
await editInput(target, ".o_field_widget input[type='text']", "limbo");
// save