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...
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.
By the way, do you know where should i search for js files containing widgets ?
GREAT thanx, you saved a lot of my precious time Jeremy :)
//============================================================= 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 ?
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.
Now i got it even better because whole address is hidden and only product name is displayed as a link :):)
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
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.