This question has been flagged
6 Replies
10043 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 ?

Avatar
Discard

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

Author

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.

Author

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

Author

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

Author

//============================================================= 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 ?

Author

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.

Author

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

Author

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

Author

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.
Best Answer

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.text(this.get("value")); 

by 

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

and it will works !

Avatar
Discard