[FIX] web: fix formatting of url field href
Before this commit, we didn't correctly detect when to prefix the value of an url field for the href of its link. closes odoo/odoo#160916 X-original-commit: 27458e3bdb545f550e60f1bd39addf188151c38b Signed-off-by: Samuel Degueldre (sad) <sad@odoo.com> Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
@@ -21,16 +21,10 @@ export class UrlField extends Component {
|
||||
}
|
||||
|
||||
get formattedHref() {
|
||||
let value = "";
|
||||
if (typeof this.props.record.data[this.props.name] === "string") {
|
||||
const shouldaddPrefix = !(
|
||||
this.props.websitePath ||
|
||||
this.props.record.data[this.props.name].includes("://") ||
|
||||
/^\//.test(this.props.record.data[this.props.name])
|
||||
);
|
||||
value = shouldaddPrefix
|
||||
? `http://${this.props.record.data[this.props.name]}`
|
||||
: this.props.record.data[this.props.name];
|
||||
let value = this.props.record.data[this.props.name];
|
||||
if (value && !this.props.websitePath) {
|
||||
const regex = /^((ftp|http)s?:\/)?\//i; // http(s)://... ftp(s)://... /...
|
||||
value = !regex.test(value) ? `http://${value}` : value;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -325,4 +325,20 @@ QUnit.module("Fields", (hooks) => {
|
||||
"Placeholder"
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("url field with non falsy, but non url value", async function (assert) {
|
||||
serverData.models.partner.fields.foo.default = "odoo://hello";
|
||||
|
||||
await makeView({
|
||||
type: "form",
|
||||
resModel: "partner",
|
||||
serverData,
|
||||
arch: `<form><field name="foo" widget="url"/></form>`,
|
||||
});
|
||||
|
||||
assert.strictEqual(
|
||||
target.querySelector(".o_field_widget[name='foo'] a").getAttribute("href"),
|
||||
"http://odoo://hello"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user