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

Hello everybody, I would like to make my form fields readonly in my model based on a condition, I'm trying it with fields_view_get for not add "attrs readonly" in each field in my xml file, I have the following code:


@api.model 

 def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):

 doc = etree.XML(res['arch']) 

 for field in res['fields']: 

 for node in doc.xpath("//field[@name='%s']" % field): 

node.set("readonly", "1") 

setup_modifiers(node, res['fields'][field]) 

res['arch'] = etree.tostring(doc) 

return res


But it doesn't work, what could be my problem? Thank you so much!

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

Where, in your code, is set variable res?

Probably you need as first line:

 res = super(YOUR_CLASS_NAME, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)

อวตาร
ละทิ้ง
ผู้เขียน

Thank You so much!! That was the error :)

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ธ.ค. 23
22925
readonly option in fields? แก้ไขแล้ว
3
ธ.ค. 23
91021
3
ก.ย. 21
5108
2
ก.ย. 18
5885
1
เม.ย. 18
3358