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

I have a simple 3-field form, and I want to make all fields required.  I have tried this:

<field name="name" required />

(Invalid XML)

and this:

<field name="name" attrs="{'required': [('id', '!=', False)]}" />

which gives this error:

Error: Unknown field id in domain [["id","!=",false]]

Every record gets an id on creation, right?  So shouldn't the second version work?  How do you make a field required at all times?

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

Hi Jeff,
Have you tried following approach

<field name="name" required="1"/>

Hope this helps :)


Cheers,
Petar

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

This works, thanks! Too bad the Odoo documentation didn't have better examples.

คำตอบที่ดีที่สุด

Add as show below

<field name="name" required=True />

 

and then convert to this as a answer......thanx

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

This gives an error. However, if you enclose "True" in quotes, it will work. Could have sworn I tried this yesterday, but it had no effect. Must be a cache thing. I restarted the server with -u and -d options to update the module and database, but, apparently, you still need to navigate to a different section of the application and come back in order to see the changes sometimes.

i will do like this and its works for me....

คำตอบที่ดีที่สุด

To make a field required, you can achieve by 2 methods:

1. WITH PY:
    _columns = {
      'name': fields.char("Name",size=64,required=1),
    }

2. WITH XML: (Same as Jeff's Suggestion)
         <field name="name" required="1"/>

NOTE: If we make the field required at PYTHON file, no need to add required at XML.

Error: Unknown field id in domain [["id","!=",false]]:
          A domain can be set for the fields that are displayed on its own view.


If you are trying to use domain = "[('categ_id','=',False)]", then 'categ_id' field should be available in their respective FORM/TREE view.
 

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ก.พ. 24
12844
1
ต.ค. 21
5653
0
มี.ค. 15
4353
1
พ.ค. 25
4148
1
มี.ค. 15
4025