Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
1344 Lượt xem

I have set some fields as required, but the red * is not displayed. Do I need to create an additional module for this?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,


You can use the following module to highlight the required fields.

https://apps.odoo.com/apps/modules/18.0/mandatory_field_highlight


Hope it helps

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

In Odoo Community Edition, required fields are automatically marked with a red asterisk (*) in the form view when the field is set as required in the model or view. Here’s how you can ensure this works correctly:

1. Use the required=True Attribute in the Model

When you define a field with required=True in your model, Odoo automatically adds a red * in the form view.

📌 Example:

python

CopyEdit

from odoo import models, fields class MyModel(models.Model): _name = 'my.model' name = fields.Char(string="Name", required=True) # Adds a red *

2. Set required="1" in the Form View (XML)

You can also specify the required attribute directly in the form view XML.

📌 Example:

xml

CopyEdit

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

Odoo will automatically display a red * next to the field label.

3. Fix Missing Red Asterisk with CSS (If Not Displayed)

In some custom themes, the red * might not appear. You can add custom CSS to enforce it:

📌 Example (SCSS in a custom module):

scss

CopyEdit

.o_required_modifier label:after { content: " *"; color: red; font-weight: bold; }

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

<field name="zip" placeholder="ZIP" required="1"/>

Make required="1" in your XML view

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 4 25
1049
3
thg 9 24
13777
2
thg 2 24
2227
1
thg 7 23
2518
2
thg 6 23
3143