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

hi all,

I have two check box(boolean). If i click one "check box1". second "check box2" should hide and vice verse should happen.

Or if i click "check box1" and if i try to click on "check box2" it should call onchange method/pop-up error message should show. 

How to do this. Please help.

Thanks in advance

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

<div attrs="{'invisible': [('bbb', '=', True)]}>
    <field name="aaa"/>
</div>
<div attrs="{'invisible': [('aaa', '=', True)]}">
    <field name="bbb"/>
</div>

Ảnh đại diện
Huỷ bỏ
Tác giả

Thank you zbik it worked

Please do not take this as an offence. This is correct and should work perfectly but imho this is not a great solution to the problem, since it only works on the view level. Anyone importing data for example will still be able on the database to set both fields to true. If there is only one value ever valid, then I would suggest going for a list or something similar. This only ever allows you to select 1 of the values.

Tác giả

thanks ludo i got your point. can we show a pop-up error message when we select another check box. how to write that "onchange" method. please help. thanks

This link should help you: https://www.odoo.com/forum/help-1/question/raise-an-error-in-odoo-8-70152#answer-70159 You replace def FOO(self) by: def onchange_FOO(self,aaa,bbb) and return result like this: result = {'value': { 'aaa': True, 'bbb': False, }}