[英]How to make selection field with widget=“priority” unhoverable or readonly in odoo 11
[英]Selection field with widget="radio" not getting required effect applied with attrs in XML file in Odoo 12
我正在嘗試使用XML 文件中的 attrs來創建一個帶有widget="radio"的選擇字段。 應用了 widget="radio" 時不需要選擇字段。 但是當我刪除收音機小部件時,選擇字段在創建新記錄時在表單視圖中獲得所需的效果。
這是我在那里申請的選擇字段:
<field name="installments_calculation" widget="radio" options="{'horizontal': true}" attrs="{'required': [('repayment_method', '=', 'salary deduction')]}"/>
這是我的repayment_method:
repayment_method = fields.Selection([('cash/bank', 'Cash/Bank'), ('salary deduction', 'Salary Deduction')])
我希望在 XML 文件中的條件下應用 required 屬性時需要選擇字段。 對於帶有 widget="radio" 的選擇字段,這種行為是否正常,或者我做錯了什么? 如果這是正常的,我怎樣才能獲得widget="radio" 所需的選擇字段?
您的代碼應該可以正常工作,但如果此問題與小部件有關,請在 Odoo Github 中報告issue
:
現在只需使用api.constrains
來獲得相同的行為
# remember to depend on both fields
@api.constrains('installments_calculation','repayment_method')
def check_installments_calculation(self):
for rec in self:
if not rec.installments_calculation and rec.repayment_method == 'salary deduction':
raise exception.ValidationError(_('You message here'))
我想出了一個解決客戶端的方法,這是我正在尋找的方法:
odoo.define('mymodule.web.radio.required', function(require){
var relational_fields = require('web.relational_fields');
relational_fields.FieldRadio.include({
isSet: function () {
return (this.mode === 'edit')? ($(this.$el).find("[checked='true']")).length > 0: this.value;
},
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.