跳至內容
選單
此問題已被標幟
2 回覆
1265 瀏覽次數

I am trying to hide a field based on an option selected from a drop down.

In my py file I have:


hide = fields.Boolean(string= 'Hide' , compute= "_compute_hide" )

@api.onchange( 'math_type_cfg_id' )

def _onchange_math_type_cfg_id(self):

    if self .math_type_cfg_id == '5' :

         self.hide = True

    else :

         self.hide = False


In my view I have:


<field name = "c_math_cfg_id"                                         

                                         required = "math_type_cfg_id == 5"

                                         invisible = "'[('hide', '=', True)]"                                       

                                         

                                         />



The required works but the field will not disappear.

Any help would be greatly appreciated!

頭像
捨棄
最佳答案

Hello, 

try :

//.py

    math_type_cfg_id = fields.Selection([

        ('1', 'Type 1'),

        ('2', 'Type 2'),

        ('3', 'Type 3'),

        ('4', 'Type 4'),

        ('5', 'Type 5'),

    ], string="Math Type")


    hide = fields.Boolean(string='Hide', compute="_compute_hide")


    @api.depends('math_type_cfg_id')

    def _compute_hide(self):

        for record in self:

            record.hide = record.math_type_cfg_id == '5'


// .xml

<field name="c_math_cfg_id"

       required="math_type_cfg_id == '5'"

       invisible="[['hide', '=', True]]"

/>


Thanks

頭像
捨棄
作者 最佳答案

I managed to resolve it.

Invisible needs to be before required and then I didn't need the on change function.


Can't close or delete the question as I do not have enough karma

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
0
8月 25
131
4
5月 25
2725
2
5月 25
6160
1
3月 25
1825
4
3月 25
4727