summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/basic
diff options
context:
space:
mode:
authorGéry Debongnie <ged@odoo.com>2018-02-09 15:47:43 +0100
committerGéry Debongnie <ged@odoo.com>2018-02-12 10:35:54 +0100
commite0cb522bf2bb1c12b2a3cce8c441a93a47685e0a (patch)
treef40b4fbbf6654c5510518926bb2538e15f8e0045 /addons/web/static/src/js/views/basic
parent9e6bc391be6e5c6e7064dcd28ebe27fe79ddba0d (diff)
[FIX] web: update form widgets when state has changed
Since the <widget> tag is not used anymore in any of our views, it was not really properly supported. In particular, the form widget was not notified when the state of the form view has changed, which makes it very difficult to actually do any useful work. With this commit, we make sure that the widget method 'updateState' (if it exists) is called with the new state whenever it changed. This should allow developers to do useful work without having to work around the issue. Note that this is not really a perfect solution, since the updateState methot may or may not have been implemented. I think that we need some kind of ViewWidget abstraction, which could be used to have a better and more complete API for widgets in a basic view. And AbstractField could inherit from ViewWidget.
Diffstat (limited to 'addons/web/static/src/js/views/basic')
-rw-r--r--addons/web/static/src/js/views/basic/basic_renderer.js6
1 files changed, 6 insertions, 0 deletions
diff --git a/addons/web/static/src/js/views/basic/basic_renderer.js b/addons/web/static/src/js/views/basic/basic_renderer.js
index f5238a95b33..204c35acaef 100644
--- a/addons/web/static/src/js/views/basic/basic_renderer.js
+++ b/addons/web/static/src/js/views/basic/basic_renderer.js
@@ -30,6 +30,7 @@ var BasicRenderer = AbstractRenderer.extend({
this.activeActions = params.activeActions;
this.viewType = params.viewType;
this.mode = params.mode || 'readonly';
+ this.widgets = [];
},
/**
* This method has two responsabilities: find every invalid fields in the
@@ -95,6 +96,9 @@ var BasicRenderer = AbstractRenderer.extend({
return this._render().then(_.constant([]));
}
+ // reset all widgets (from the <widget> tag) if any:
+ _.invoke(this.widgets, 'updateState', state);
+
var defs = [];
// Reset all the field widgets that are marked as changed and the ones
@@ -605,6 +609,8 @@ var BasicRenderer = AbstractRenderer.extend({
var Widget = widgetRegistry.get(node.attrs.name);
var widget = new Widget(this, record);
+ this.widgets.push(widget);
+
// Prepare widget rendering and save the related deferred
var def = widget.__widgetRenderAndInsert(function () {});
if (def.state() === 'pending') {