When an attribute has an option where "Is custom value" is selected, a text box will show when the customer selects that option. Is there anyway for that text box be required?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- ลูกค้าสัมพันธ์
- e-Commerce
- ระบบบัญชี
- สินค้าคงคลัง
- PoS
- Project
- MRP
คำถามนี้ถูกตั้งค่าสถานะ
Hii,
Yes, you can make a text box required only when the "Is custom value" option is selected in Odoo. This is a classic case of conditional field requirement.
Model Code (Python):
from odoo import models, fields, api
class YourModel(models.Model):
_name = 'your.model'
attribute_value = fields.Selection([
('option1', 'Option 1'),
('custom', 'Custom Value')
], string="Attribute Value")
custom_value_text = fields.Char("Custom Value Text")
is_custom_value = fields.Boolean("Is Custom", compute="_compute_is_custom_value")
@api.depends('attribute_value')
def _compute_is_custom_value(self):
for rec in self:
rec.is_custom_value = rec.attribute_value == 'custom'
@api.constrains('attribute_value', 'custom_value_text')
def _check_custom_value_required(self):
for rec in self:
if rec.attribute_value == 'custom' and not rec.custom_value_text:
raise ValidationError("Custom value must be provided when 'Custom' is selected.")
View Code (XML):
<field name="attribute_value"/>
<field name="custom_value_text"
invisible = [('attribute_value', '!=', 'custom')], 'required': [('attribute_value', '=', 'custom')] />
i hope it is use full
สนุกกับการพูดคุยนี้ใช่ไหม? เข้าร่วมเลย!
สร้างบัญชีวันนี้เพื่อเพลิดเพลินไปกับฟีเจอร์พิเศษและมีส่วนร่วมกับคอมมูนิตี้ที่ยอดเยี่ยมของเรา!
ลงชื่อRelated Posts | ตอบกลับ | มุมมอง | กิจกรรม | |
---|---|---|---|---|
Discount Free Gift
แก้ไขแล้ว
|
|
4
ส.ค. 25
|
1608 | |
|
2
ก.ย. 25
|
900 | ||
Variant Purchase Price
แก้ไขแล้ว
|
|
1
มิ.ย. 25
|
1824 | |
|
1
มิ.ย. 25
|
1205 | ||
|
2
พ.ค. 25
|
1588 |