summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js
diff options
context:
space:
mode:
authorDavid Monjoie <dmo@odoo.com>2017-03-07 16:34:32 +0100
committerAaron Bohy <aab@odoo.com>2017-04-11 19:44:38 +0200
commit38300a9bb810580f800afd053973e7a33d2fe663 (patch)
tree1cf77897a716d047c5a9c10e429dc684b2bd1f21 /addons/web/static/src/js
parent160dd6a7e601d7b6fa2fd4b27ac08ff851deb364 (diff)
[FIX] web: prevent onchanges from re-rendering the current field
Input fields should not be re-rendered by the onchange mechanism as they might exhibit formatting that you do not want to have when typing. The list view was not propagating the original event to the lower functions like the form view does, so I added it there.
Diffstat (limited to 'addons/web/static/src/js')
-rw-r--r--addons/web/static/src/js/fields/basic_fields.js15
-rw-r--r--addons/web/static/src/js/views/list/list_controller.js5
-rw-r--r--addons/web/static/src/js/views/list/list_editable_renderer.js16
3 files changed, 30 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 12699658a7b..6600dbffb0c 100644
--- a/addons/web/static/src/js/fields/basic_fields.js
+++ b/addons/web/static/src/js/fields/basic_fields.js
@@ -46,6 +46,21 @@ var InputField = AbstractField.extend({
setTimeout(this.$el.select.bind(this.$el), 0);
},
+ /**
+ * Do not re-render this field if it was the origin of the onchange call.
+ * FIXME: make the onchange work on itself without disturbing the user typing
+ *
+ * @override
+ */
+ reset: function (record, event) {
+ this._reset(record, event);
+ if (event && event.target === this) {
+ return $.when();
+ } else {
+ return this._render();
+ }
+ },
+
//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------
diff --git a/addons/web/static/src/js/views/list/list_controller.js b/addons/web/static/src/js/views/list/list_controller.js
index 5aacda363f8..2e764214459 100644
--- a/addons/web/static/src/js/views/list/list_controller.js
+++ b/addons/web/static/src/js/views/list/list_controller.js
@@ -167,10 +167,11 @@ var ListController = BasicController.extend({
*
* @param {string} id a basicmodel id, which is a record in the list view
* @param {string[]} fields the changed fields
+ * @param {OdooEvent} event the event that triggered the change
*/
- _confirmChange: function (id, fields) {
+ _confirmChange: function (id, fields, event) {
var state = this.model.get(this.handle);
- this.renderer.confirmChange(state, id, fields);
+ this.renderer.confirmChange(state, id, fields, event);
},
/**
* This function is the hook called by the field manager mixin to confirm
diff --git a/addons/web/static/src/js/views/list/list_editable_renderer.js b/addons/web/static/src/js/views/list/list_editable_renderer.js
index d6bbdd65fd6..9e83a45a5fc 100644
--- a/addons/web/static/src/js/views/list/list_editable_renderer.js
+++ b/addons/web/static/src/js/views/list/list_editable_renderer.js
@@ -90,12 +90,13 @@ ListRenderer.include({
* @param {Object} state a record resource (the new full state)
* @param {string} changedRecordID the local id for the changed record
* @param {string[]} changedFields list of modified fields
+ * @param {OdooEvent} event the event that triggered the change
*/
- confirmChange: function (state, changedRecordID, changedFields) {
+ confirmChange: function (state, changedRecordID, changedFields, event) {
this.state = state;
var rowIndex = _.findIndex(this.state.data, {id: changedRecordID});
if (rowIndex > -1) {
- this._updateRow(rowIndex, changedFields);
+ this._updateRow(rowIndex, changedFields, event);
} else {
this._render();
}
@@ -416,13 +417,20 @@ ListRenderer.include({
}
$td.replaceWith($new_td);
},
- _updateRow: function (index, changed_fields) {
+ /**
+ * Updates the row of a particular record of the editable list view.
+ *
+ * @param {index} index the index of the record whose row needs updating
+ * @param {string[]} changed_fields names of the fields which changed
+ * @param {OdooEvent} event the event that triggered the change
+ */
+ _updateRow: function (index, changed_fields, event) {
var self = this;
var record = this.state.data[index];
_.each(changed_fields, function (field_name) {
var widget = _.findWhere(self.widgets, {name: field_name});
if (widget && widget.__rowIndex === index) {
- widget.reset(record);
+ widget.reset(record, event);
widget.$el.parent().addClass('o_field_dirty');
} else {
var column_index = _.findIndex(self.columns, function (column) {