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

Hello everyone,

I have 2 fields, a Boolean field and a float field so, whenever user tick on Boolean field user can set a custom value in float field and whenever user untick on Boolean field, float field set 0 value automatic. How to do this?



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

Hi,

    Try using api.onchange

In py, 

    @api.onchange('boolean_field')

    def onchange_boolean_field(self):

        if self.boolean_field:

            self.float_field = 1     //Here i have set default value to 1 when you tick the boolean field 

        else:    

            self.float_field = 0.00

In xml,

<fields name="boolean_field"/>

<fields name="float_field" attrs="{'readonly': [('boolean_field', '!=', True)]}"/>   // Here if boolean field is not ticked  then zero is set and float field is made readonly

Hope it helps,

Thanks!!

 

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

its working. Thank you so much for your help :)

Happy to help!

Please mark it as correct answer if its working properly,

Thanks again!!

Be aware that onchange will soon be deprecated