Odoo Help


URL widget

Dr Obx
on 3/20/15, 10:00 AM 2,622 views

Hello there,

Apparently it is a serious problem and nobody know how to do it  so I need help, I'm new in Odoo, it's still a mistery for me how to build something in this system.

How can I create and how should it look like a function which will create a link. For example I have a field "ebay_number" which contain 12 digits long number of product and I would like to create a link to the item based on constant element like "www.ebay.com/itm/ + <item number>"  but on screen I want only see this number. Hope you understand guys what I'm talking about.

Can anyone help me with it please?

Too complicated ?

Can anyone show me how to do it ?

Take a look here : https://www.odoo.com/documentation/8.0/howtos/web.html#the-form-view-fields...

Jérémy Kersten (jke)
on 3/21/15, 6:42 AM

Thank you Jeremy, it might be useful but like i said, I'm new in Odoo so even if i know something about JS HTML and other stuff I don't really know how to combine it together. In PHP is piece of cake but modyfying existing js code is completely different thing.

Dr Obx
on 3/21/15, 1:19 PM

By the way, do you know where should i search for js files containing widgets ?

Dr Obx
on 3/21/15, 1:26 PM

GREAT thanx, you saved a lot of my precious time Jeremy :)

Dr Obx
on 3/21/15, 6:30 PM

//============================================================= instance.web.form.FieldLink = instance.web.form.FieldChar.extend({ template: 'FieldLink', initialize_content: function() { this._super(); var $button = this.$el.find('button'); $button.click(this.on_button_clicked); this.setupFocus($button); }, render_value: function() { if (!this.get("effective_readonly")) { this._super(); } else { var tmp = this.get('value'); var s = /(\w+):(.+)|^\.{0,2}\//.exec(tmp); if (!s) { tmp = "http://www.ebay.co.uk/itm/" + this.get('value'); } var text = this.get('value') ? this.node.attrs.text || tmp : ''; this.$el.find('a').attr('href', tmp).text(text); } }, on_button_clicked: function() { if (!this.get('value')) { this.do_warn(_t("Resource Error"), _t("This resource is empty")); } else { var url = $.trim(this.get('value')); if(/^www\./i.test(url)) url = 'http://www.ebay.co.uk/itm/'+ this.get('value'); window.open(url); } } }); What do you think ? Will it work ?

Dr Obx
on 3/21/15, 8:53 PM

Finally i did it. But i made one step further to keep old widget untouched I created a separate widget for this purpose. Now i have a special widget for Ebay :) and finally i know how i can make some more depending on what I will need. And this is the best option.

Dr Obx
on 3/22/15, 4:22 PM

Now i got it even better because whole address is hidden and only product name is displayed as a link :):)

Dr Obx
on 3/25/15, 6:40 PM

I just created a new widget and the code you suggested in my widget looks like: this.$el.find('a').attr('href', tmp).text(this.get('value')); and works perfectly fine ;) Thanx

Dr Obx
on 3/25/15, 6:46 PM

By the way Jeremy, string you asked me to change doesn't exist in Odoo8.0 or I can't find (blindness ?) I've found only this.$el.find('a').attr('href', tmp).text(text); is this the string you've had in mind ? What i've done: var suf = document.getElementById('id'); if (suf = 'ebay'){ var suf_x = 'http://

'; tmp = suf_x + this.get('value');} var text = this.get('value') ? this.node.attrs.text || tmp : ''; this.$el.find('a').attr('href', tmp).text(this.get('value')); At the end getting only a name on screen but link is generated correctly so that's what i wanted.
Dr Obx
on 3/28/15, 10:58 AM

Jérémy Kersten (jke)

--Jérémy Kersten (jke)--

| 3 3 5
Jodoigne, Belgium
--Jérémy Kersten (jke)--

Jérémy is a member of the core R&D team since september 2013. He developed several projects for OpenERP version 8 including the eCommerce, the Google Calendar synchronization and the new product variants/configurator. Now, he manages Odoo website and themes for saas.

Jérémy Kersten (jke)
On 3/21/15, 6:35 PM

in view_form.js you have all basic widget... If you need module which add a widget, you can grep 'instance.web.form.widgets = '...

But your widget is really basic, you can copy past the widget Field2 from documentation...

replace the



this.$el.html("<a href='<your_url>/'>"+ this.get("value") + "</a>");

and it will works !

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

3 follower(s)


Asked: 3/20/15, 10:00 AM
Seen: 2622 times
Last updated: 7/16/15, 9:57 AM