summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/fields
diff options
context:
space:
mode:
Diffstat (limited to 'addons/web/static/src/js/fields')
-rw-r--r--addons/web/static/src/js/fields/abstract_field.js24
-rw-r--r--addons/web/static/src/js/fields/basic_fields.js7
2 files changed, 31 insertions, 0 deletions
diff --git a/addons/web/static/src/js/fields/abstract_field.js b/addons/web/static/src/js/fields/abstract_field.js
index 735e12a3861..9bb61475b83 100644
--- a/addons/web/static/src/js/fields/abstract_field.js
+++ b/addons/web/static/src/js/fields/abstract_field.js
@@ -172,6 +172,12 @@ var AbstractField = Widget.extend({
// calls to the format (resp. parse) function.
this.formatOptions = {};
this.parseOptions = {};
+
+ // if we add decorations, we need to reevaluate the field whenever any
+ // value from the record is changed
+ if (this.attrs.decorations) {
+ this.resetOnAnyFieldChange = true;
+ }
},
/**
* Loads the libraries listed in this.jsLibs and this.cssLibs
@@ -332,6 +338,21 @@ var AbstractField = Widget.extend({
//--------------------------------------------------------------------------
/**
+ * Apply field decorations (only if field-specific decorations have been
+ * defined in an attribute).
+ *
+ * @private
+ */
+ _applyDecorations: function () {
+ var self = this;
+ this.attrs.decorations.forEach(function (dec) {
+ var isToggled = py.PY_isTrue(
+ py.evaluate(dec.expression, self.record.evalContext)
+ );
+ self.$el.toggleClass(dec.className, isToggled);
+ });
+ },
+ /**
* Converts the value from the field to a string representation.
*
* @private
@@ -377,6 +398,9 @@ var AbstractField = Widget.extend({
* @returns {Deferred|undefined}
*/
_render: function () {
+ if (this.attrs.decorations) {
+ this._applyDecorations();
+ }
if (this.mode === 'edit') {
return this._renderEdit();
} else if (this.mode === 'readonly') {
diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js
index 31b0c53dd64..01b4cb4371d 100644
--- a/addons/web/static/src/js/fields/basic_fields.js
+++ b/addons/web/static/src/js/fields/basic_fields.js
@@ -206,6 +206,13 @@ var InputField = DebouncedField.extend({
this.isDirty = false;
}
if (this.isDirty || (event && event.target === this && event.data.changes[this.name] === this.value)) {
+ if (this.attrs.decorations) {
+ // if a field is modified, then it could have triggered an onchange
+ // which changed some of its decorations. Since we bypass the
+ // render function, we need to apply decorations here to make
+ // sure they are recomputed.
+ this._applyDecorations();
+ }
return $.when();
} else {
return this._render();