繼承視圖 - 將屬性 maxlength 添加到 char(在 Web 中輸入文本)欄位 Avatar Victor Torralba 24 mayo 2022 viewsinheritanceattributes
您好,我正在嘗試將屬性 maxlength="100" 添加到產品表單的描述欄位中。
我已經完成了繼承,還修改了“占位符”值,并向元素添加了一個新類“邊框”。
但我無法定義 maxlength=10。
這是代碼:
<odoo>
<data>
<record id="inherit_view_product_template_product_form" model="ir.ui.view">
<field name="name">inherit_view_product_template_product.form</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view" />
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="attributes">
<field name="name" placeholder="Max length 10 chars">
<attribute name="class" add="border" remove="" separator=" " />
<attribute name="maxlength" add="10" remove="" separator=" " />
</field>
</xpath>
</field>
</record>
</data>
</odoo>
我錯過了什么?
謝謝你的幫助。
uj5u.com熱心網友回復:
你不能從 做xml,你可以做的是:
- 如果大小超過特定數字,則使用約束顯示錯誤訊息,一旦單擊保存按鈕,就會出現此錯誤:
@api.constrains('name')
def _check_name(self):
for product in self:
if len(product.name) > 10:
raise ValidationError('The name of product must be less than or equal 10 characters')
- 您可以在欄位級別設定 size 屬性:
name = fields.Char('Name', index=True, required=True, translate=True, size=10)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/483358.html
下一篇:如何宣告稍后可用的Cocoa類?
