summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/fields/basic_fields.js
diff options
context:
space:
mode:
authorqsm-odoo <qsm@odoo.com>2017-03-30 10:59:32 +0200
committerAaron Bohy <aab@odoo.com>2017-04-11 19:44:38 +0200
commitef52914ea2b73b5f33c1020a823085ec82198c09 (patch)
tree5dd61ce79151e48da4896011ce16297539efe080 /addons/web/static/src/js/fields/basic_fields.js
parentc60743428d9c47af1f18a331ebeadaebb23e3d4c (diff)
[REF] web: properly confirm value change of debounced input field
Input fields notify their changes when the user is typing text at a rate of max 1 per second (by default) and when a change is confirmed. This last case was handled by listening to the "focusout" event. The "change" event is however more suited to handle that. This commit also solves a problem with the related test. Before this commit, the test triggered some "input" events on an <input/>, then waited some time so that the debounced action is executed, then restarted triggering events... the problem is that this "some time" was long enough to trigger the onchange but not necessarily long enough to be sure another onchange can be started. Indeed, the mockserver get rid of RPC delays but not of CPU delay. As two subsequent onchange cannot be done at the same time (the second one is done after the first one is finished (see Mutex)) and that this test simulates a 3ms delay for the onchange, there is no guarantee that waiting x ms (even > 3ms) will be enough, indeed sometimes we had this sequence: 1) trigger "input" event 2) trigger "input" event 3) start delay of 75ms 4) debouncing time (3ms) is finished: call `_setValue` 5) basic model mutex (already resolved) 6) start async onchange RPC 7) (1) -> (6) took more than 75ms CPU time, the delay started in (3) is finished: trigger "change" event 8) call `_setValue` (no debouncing of "change" events) 9) basic model mutex... NOT resolved as the async onchange RPC started in (6) did not had the opportunity to continue its call sequence (no matter the time it would take) To solve this problem, the 75ms delay had to be replaced by a non arbitrary waiting: the mutex resolution. As the test does not know about this mutex, the only way to be sure it is finished is to wait for the `mockRPC` to be finished thanks to a deferred and then wait for another callstack to be completed thanks to a 0ms delay.
Diffstat (limited to 'addons/web/static/src/js/fields/basic_fields.js')
-rw-r--r--addons/web/static/src/js/fields/basic_fields.js7
1 files changed, 4 insertions, 3 deletions
diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js
index 245643ece57..3ec0c027c77 100644
--- a/addons/web/static/src/js/fields/basic_fields.js
+++ b/addons/web/static/src/js/fields/basic_fields.js
@@ -30,7 +30,7 @@ var _t = core._t;
var InputField = AbstractField.extend({
events: _.extend({}, AbstractField.prototype.events, {
'input': '_onInput',
- 'focusout': '_onFocusout',
+ 'change': '_onChange',
}),
/**
@@ -137,11 +137,12 @@ var InputField = AbstractField.extend({
//--------------------------------------------------------------------------
/**
- * We immediately notify the outside world when this input loses focus.
+ * We immediately notify the outside world when this input confirms its
+ * changes.
*
* @private
*/
- _onFocusout: function () {
+ _onChange: function () {
this._setValue(this.$input.val());
},
/**