Odoo Help

Welcome!

This community 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.

1

How to apply widget="URL" based on a condition?

By
AJ Schrafel Paper Corp
on 7/22/13, 11:37 AM 1,979 views

I have a field in my XML that is sometimes a URL, sometimes a phone number. I want to apply the widget="url" when the field contains a website but not when the field contains a phone number. I have a second field that tells the user whether the field contains a phone number of website.

<field name="openerp_val" widget="url" string ="openerp_val" attrs="{'invisible': [('field_diff','=','website')]}"/>
<field name="openerp_val" string ="openerp_val" attrs="{'invisible': [('field_diff','!=','website')]}"/>

I have tried the above and will only show the type of field in the bottom line of code. I think the second line is over writing the first line.

So how can i have a field displayed iwth a widget like url based on a condition?

2
Abhishek
On 7/22/13, 1:29 PM

Hi,

I think it will be better if you create two field (in py file openerp_val1 & openerp_val2 with same property then in xml like this )

<field name="openerp_val1" widget="url" string="openerp_val" attrs="{'invisible': [('field_diff','=','website')]}"/>

<field name="openerp_val2" string="openerp_val" attrs="{'invisible': [('field_diff','!=','website')]}"/>

then try it will work... I also tried with same field but its not taking two same field at a time it is only considering last one .

this answer would display the desired result, but it seems more like a work around rather than a solution. No way to conditionally display something as a URL?

AJ Schrafel Paper Corp
on 7/22/13, 6:43 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 7/22/13, 11:37 AM
Seen: 1979 times
Last updated: 3/16/15, 8:10 AM