From d5d2c5524c0890e0d89ff2029995bb4bed941421 Mon Sep 17 00:00:00 2001 From: Dhruv Patel Date: Tue, 17 Dec 2019 09:31:20 +0000 Subject: [FIX] base,web: url widget: add protocol in href With this commit, the url widget automatically prefixes the href url by http:// if no protocol is specified, so that clicking on the url will by default redirect to an external website. To prevent this behavior, one can still specify the new option 'website_path: true' on the url field node in the view arch. Thanks to this, we can remove a similar logic (only implemented on res_partner model) which automatically altered the value saved in database to force its 'http://' prefix. task-2153184 closes odoo/odoo#42118 Signed-off-by: Aaron Bohy (aab) --- addons/web/static/src/js/fields/basic_fields.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'addons/web/static/src/js/fields/basic_fields.js') diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index 0d1fc77737f..996e759a70a 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -1528,6 +1528,7 @@ var UrlWidget = InputField.extend({ init: function () { this._super.apply(this, arguments); this.tagName = this.mode === 'readonly' ? 'a' : 'input'; + this.websitePath = this.nodeOptions.website_path || false; }, //-------------------------------------------------------------------------- @@ -1555,10 +1556,15 @@ var UrlWidget = InputField.extend({ * @private */ _renderReadonly: function () { + let href = this.value; + if (this.value && !this.websitePath) { + const regex = /^(?:[fF]|[hH][tT])[tT][pP][sS]?:\/\//; + href = !regex.test(this.value) ? `http://${href}` : href; + } this.$el.text(this.attrs.text || this.value) .addClass('o_form_uri o_text_overflow') .attr('target', '_blank') - .attr('href', this.value); + .attr('href', href); }, //-------------------------------------------------------------------------- -- cgit v1.2.3