[IMP] web: add decoration support for all field widgets (#25160)

It is sometimes useful to be able to customize slightly the color of a
field depending on some conditions on the current record.

For example, imagine that we want to show a VAT number field in green/red, if
it was validated or not. To do that, we can add a field with an
onchange, and simply add decoration-danger and decoration-success
attributes to the field.
This commit is contained in:
oco-odoo
2018-06-08 15:20:49 +02:00
committed by GitHub
parent a8aa0bcbbe
commit d4cd8be48f
7 changed files with 146 additions and 10 deletions
+28
View File
@@ -1358,6 +1358,34 @@ Let us mention the most important ones:
- the field widgets can be used outside of a view. Their API is slightly
awkward, but they are designed to be standalone.
Decorations
-----------
Like the list view, field widgets have a simple support for decorations. The
goal of decorations is to have a simple way to specify a text color depending on
the record current state. For example,
.. code-block:: xml
<field name="state" decoration-danger="amount &lt; 10000"/>
The valid decoration names are:
- decoration-bf
- decoration-it
- decoration-danger
- decoration-info
- decoration-muted
- decoration-primary
- decoration-success
- decoration-warning
Each decoration *decoration-X* will be mapped to a css class *text-X*, which is
a standard bootstrap css class (except for *text-it* and *text-bf*, which are
handled by odoo and correspond to italic and bold, respectively). Note that the
value of the decoration attribute should be a valid python expression, which
will be evaluated with the record as evaluation context.
Non relational fields
---------------------