Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
5056 มุมมอง

Hi,


I'm testing an upgrade to Odoo 16 and I've seen that these classes no longer work. They're still included in the documentation: https://www.odoo.com/documentation/16.0/developer/reference/backend/views.html#


Is there an alternative to show/hide fields depending if the user is currently editing or just reading the form?


Thank you!

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Yes, you're right. The oe_edit_only and oe_read_only classes are no longer available in Odoo 16. Instead, you can use the attrs attribute in the field definition to show/hide fields depending on whether the user is editing or just reading the form.

Here is an example of how you can use the attrs attribute to show/hide a field:

field_name = fields.Char(string="Field Name", readonly=True, states={'edit': [('readonly', False)]})

In this example, the readonly attribute is set to True, which means that the field is read-only by default. However, if the user is editing the form, the readonly attribute is set to False using the states attribute.

You can also use the attrs attribute to show/hide fields based on other conditions. For example, you can show/hide a field based on the value of another field:

other_field = fields.Boolean(string="Other Field")

field_name = fields.Char(string="Field Name", attrs={'invisible': [('other_field', '=', True)]})

In this example, the field_name field is hidden when the other_field field is set to True.

You can find more information about the attrs attribute in the Odoo documentation: https://www.odoo.com/documentation/16.0/reference/orm.html#field-attributes.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
Inverse of css class oe_edit_only? แก้ไขแล้ว
12
ส.ค. 20
24441
Web Module not loading the css แก้ไขแล้ว
2
มี.ค. 15
22031
How to center the header of a tree view แก้ไขแล้ว
2
มิ.ย. 24
19756
2
มี.ค. 15
5183
V17 Tree, Form view แก้ไขแล้ว
1
มี.ค. 25
1389