From d4cd8be48f83a7775c667bc6c968a4b9e14679be Mon Sep 17 00:00:00 2001 From: oco-odoo Date: Fri, 8 Jun 2018 15:20:49 +0200 Subject: [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. --- addons/web/static/src/js/views/basic/basic_view.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'addons/web/static/src/js/views/basic/basic_view.js') diff --git a/addons/web/static/src/js/views/basic/basic_view.js b/addons/web/static/src/js/views/basic/basic_view.js index 22900e12d6b..2c4ed711223 100644 --- a/addons/web/static/src/js/views/basic/basic_view.js +++ b/addons/web/static/src/js/views/basic/basic_view.js @@ -209,6 +209,18 @@ var BasicView = AbstractView.extend({ var self = this; attrs.Widget = this._getFieldWidgetClass(viewType, field, attrs); + // process decoration attributes + _.each(attrs, function (value, key) { + var splitKey = key.split('-'); + if (splitKey[0] === 'decoration') { + attrs.decorations = attrs.decorations || []; + attrs.decorations.push({ + className: 'text-' + splitKey[1], + expression: py.parse(py.tokenize(value)) + }); + } + }); + if (!_.isObject(attrs.options)) { // parent arch could have already been processed (TODO this should not happen) attrs.options = attrs.options ? pyeval.py_eval(attrs.options) : {}; } -- cgit v1.2.3