summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/fields
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2017-05-05 15:21:36 +0200
committerAaron Bohy <aab@odoo.com>2017-05-08 08:10:00 +0200
commitc04b840a45edd222c50e74d18e2d02a3dd3175cd (patch)
treecde51a1ba7c2eb0d869b9be711e8011158fb85fd /addons/web/static/src/js/fields
parentc75680c527844b3b984fa6dfbe04b612528cd9fb (diff)
[FIX] web: FieldMonetary: don't loose focus after edition
... in x2many editable list views. Field widgets can detect that they are at the origin of a field_changed event, so that they don't re-render themselves when they are being edited. This didn't work for fields inside x2many list views. This wasn't a big problem for most of the fields, because the cursor position was automatically reset after a re-rendering, but it wasn't working for monetary fields that empty their $el before each re-rendering. This rev. fixes the issue by making the field widgets inside x2many list able to detect that they are the origin of a change, and thus removes the now useless code that restore the cursor position.
Diffstat (limited to 'addons/web/static/src/js/fields')
-rw-r--r--addons/web/static/src/js/fields/basic_fields.js5
-rw-r--r--addons/web/static/src/js/fields/relational_fields.js9
2 files changed, 8 insertions, 6 deletions
diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js
index b3defa97911..fc4af105865 100644
--- a/addons/web/static/src/js/fields/basic_fields.js
+++ b/addons/web/static/src/js/fields/basic_fields.js
@@ -229,12 +229,7 @@ var InputField = DebouncedField.extend({
type: 'text',
placeholder: this.attrs.placeholder || "",
});
- // Save cursor position to restore it after updating value
- var selectionStart = this.$input[0].selectionStart;
- var selectionEnd = this.$input[0].selectionEnd;
this.$input.val(this._formatValue(this.value));
- this.$input[0].selectionStart = selectionStart;
- this.$input[0].selectionEnd = selectionEnd;
return this.$input;
},
/**
diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js
index e9fa7dd09d1..db2db031a15 100644
--- a/addons/web/static/src/js/fields/relational_fields.js
+++ b/addons/web/static/src/js/fields/relational_fields.js
@@ -600,7 +600,7 @@ var FieldX2Many = AbstractField.extend({
if (command.operation === 'UPDATE') {
var state = record.data[this.name];
var fieldNames = state.getFieldNames();
- this.renderer.confirmChange(state, command.id, fieldNames);
+ this.renderer.confirmChange(state, command.id, fieldNames, ev.initialEvent);
return $.when();
}
}
@@ -787,12 +787,19 @@ var FieldX2Many = AbstractField.extend({
*/
_onFieldChanged: function (ev) {
if (ev.target === this) {
+ ev.initialEvent = this.lastInitialEvent;
return;
}
ev.stopPropagation();
// changes occured in an editable list
var changes = ev.data.changes;
+ // save the initial event triggering the field_changed, as it will be
+ // necessary when the field triggering this event will be reset (to
+ // prevent it from re-rendering itself, formatting its value, loosing
+ // the focus... while still being edited)
+ this.lastInitialEvent = undefined;
if (Object.keys(changes).length) {
+ this.lastInitialEvent = ev;
this._setValue({
operation: 'UPDATE',
id: ev.data.dataPointID,