Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
2 Antworten
1242 Ansichten

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!

Avatar
Verwerfen
Beste Antwort

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

Avatar
Verwerfen
Autor Beste Antwort

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

Avatar
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
4
Mai 25
2705
2
Mai 25
6137
1
März 25
1811
4
März 25
4702
3
Feb. 25
5773