Reputation: 537
I would like to add an alert in an on-change method, but without raising warning or user error. Just showing a like-bootstrap alert, without interrupting the possibility of the user to save the data. Similar to what happens when an invoice is validated.
How to do that please?
Upvotes: 3
Views: 1687
Reputation: 2351
I don't know if this is the best way to do it but this worked for me.
In your views, place a bootstrap alert inside your xml field:
<field name="arch" type="xml">
<form string="My Form">
<div class="alert alert-success alert-dismissible" invisible="not context.get('show_message', False)">
<a href="#" class="close" data-dismiss="alert" aria-label="close">X</a>
<strong>Success!</strong> Indicates a successful or positive action.
</div>
...
Notice the invisible
attribute in the div
element. So in your model, when handling an action, you can pass a variable show_message
in the context. This worked for me:
@api.multi
def my_action(self):
return {
"type": "ir.actions.act_window",
"res_model": "my_module.my_model",
"views": [[False, "form"]],
"res_id": self.id,
"target": "main",
"context": {'show_message': True},
}
Upvotes: 1