[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.
This commit is contained in:
David Monjoie
2017-04-11 19:44:38 +02:00
committed by Aaron Bohy
parent 160dd6a7e6
commit 38300a9bb8
3 changed files with 30 additions and 6 deletions
@@ -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
//--------------------------------------------------------------------------
@@ -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
@@ -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) {