Skip to Content
Menu
This question has been flagged
1 Reply
1563 Views

Hi,

we use odoo 9 community.

I have two fields, city_id and state_id.
I want a message to be displayed when the user selects the city before selecting the state.

In fact, when the state_id field is empty and the user clicks on the city_id field, a message should be displayed.
please help me.

Thanks.

Avatar
Discard
Best Answer

Hi,

You can use the method onchange to check when state_id field is empty or not.

from odoo.exceptions import UserError

@api.onchange('city_id')
def onchange_city_id(self):
if not self.state_id:
raise UserError(_('State is empty, please fill it.'))

Best regards!

Avatar
Discard