This question has been flagged
12 Replies
25530 Views

Hi, further to : a question I asked before I would like to know:

how can we deduct the state of a form (either edit or view mode) in xml view definition ?

I would like to use this information in a an attribute on field: example:

<field name="my_field" invisible="isTheViewInEditMode">
<field name="my_field" attrs="{'tree_invisible':[domain using isTheViewInEditMode]}">
Avatar
Discard
Best Answer

The Solution might be class="oe_edit_only".

<field name="yourfield" class="oe_edit_only"/>

This will hide the field, when view is in view mode. oe_edit_only also works for other design elements like labels, groups, etc..

Avatar
Discard

To achieve the opposite (hide in edit mode), the answer to this question is very helpful and works fine for me:

http://help.openerp.com/question/11853/inverse-of-css-class-oe_edit_only/

Best Answer

First thing i can not understand well what you want to do but i try to do what i understood.

I add attrs field in sale order lines like this

<field name="discount" attrs="{'invisible':[('price_unit','=',0)]}" groups="sale.group_discount_per_so_line"/>

This means my discount field become invisible if price_unit = 0 And that's working See in image

image description

And if you wish user can see the field but can't edit then better use readonly attribute

Hope this will help you

Avatar
Discard
Author

Hey Parth, Thanks for your answer, my goal is the following: in a listview child of a form view (one2many widget) I have one fields.text that holds a lot of text. Since there is no option to truncate the text shown when the whole form is in view mode, I did as advised in another post. I created a fields.function that returns a truncated version of my fields.text. Now, I want to have the fields.text to be visible in the listview when the form is in edit mode only, and the fields.function (truncated text) to be visible when the form is in view mode.

Author

in the previous post mentionned in my question, someone advised setting the invisble attribute with invisible="context.get('set_editable',False)" but I found out that the set_editable key is not in the context. Therefore I want to clarify within this post : is there a way to find out in what state (edit|view) a form is at all ?

Means you want to enable and disable whole column during switching between edit and saved mode .... I don't know about Is there a way to find out in what state (edit|view) a form is at all ?

But one other thing is pass class="oe_edit_only" this will disable field in saved mode and display that field in edit mode. but i never try that on one2many. Try it and see what happen

Author

that was a good track at first but so far it has no effect. Though the css trick should be investigated. I actually tried it on a label and it didn't affect visibility, even though the class was on the dom element.

Author

correction : it does work on a label, I had initially tested on a validated sale.order that could not be edited anymore, therefore not in edit mode. But on a draft sale.order it worked on a label. It still doesn't work on a table column though.

Then there are 2 options .........

First made own widget(this is hard) .......

Second easiest way is use Jquery And JavaScript

For Local Jquery and javascript See this link Local CSS,JQuery and javascript in Openerp

Author

ok, so no easy way then. Thanks for the help anw !

Author

Back to this topic, I looked through the CSS but didn't spot a class that does the opposite like class="oe_browse_only" ... any hint ?

Best Answer

Even a couple of years later I found it very useful. It still can help :)

Currently added an image which is overlapping product avatar but while editing record I couldn't add/change avatar because product avatar was covered by the image i added :)

So I was needed something to solve this issue. Right  after I added this class="oe_edit_only" overlapping image gets hidden so i can add/change product's avatar now :)


in edit mode:

in view mode:

"in stock"

in view mode:

"out of stock"


Thank you guys :)

Avatar
Discard

I'd love to see some example code of this Dr Obx!

What do you mean ?
Example of what ?

On 27 July 2015 at 15:37, Atte Isopuro <atte.isopuro@web-veistamo.fi> wrote:

I'd love to see some example code of this Dr Obx!

--
Atte Isopuro
Sent by Odoo S.A. using Odoo about Forum Post False