summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2017-02-27 15:46:13 +0100
committerAaron Bohy <aab@odoo.com>2017-04-11 19:44:38 +0200
commit95cbf1d37b163d86dc68ebdbee2b45d3cb2e2700 (patch)
tree3d68cfa998953926d44d8d555ef6192eb893ff2a
parentb997309cf694cbd5e8484c9516d7055fc5b1180c (diff)
[FIX] web: list_editable_renderer: don't instantiate widgets twice
In an editable list view, if there was a readonly field in the table, positionned before editable fields, clicking on that readonly field resulted in the editable field widgets being re-instantiated and appended to the DOM (so there were several widgets per fields/cells).
-rw-r--r--addons/web/static/src/js/views/list/list_editable_renderer.js2
-rw-r--r--addons/web/static/test/views/list_tests.js38
2 files changed, 39 insertions, 1 deletions
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 7be3f3d4e29..38b3066a4d3 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
@@ -366,7 +366,7 @@ ListRenderer.include({
// if we are just changing active cell in the same row, activate the
// corresponding widget and return
- if (rowIndex === this.currentRow && colIndex !== this.currentCol) {
+ if (rowIndex === this.currentRow) {
var w = _.findWhere(this.widgets, {
__rowIndex: rowIndex,
__colIndex: colIndex
diff --git a/addons/web/static/test/views/list_tests.js b/addons/web/static/test/views/list_tests.js
index 269412036c8..0401f555573 100644
--- a/addons/web/static/test/views/list_tests.js
+++ b/addons/web/static/test/views/list_tests.js
@@ -970,6 +970,44 @@ QUnit.module('Views', {
"should have formatted the datetime");
list.destroy();
});
+
+ QUnit.test('edit a row by clicking on a readonly field', function (assert) {
+ assert.expect(8);
+
+ this.data.foo.fields.foo.readonly = true;
+
+ var list = createView({
+ View: ListView,
+ model: 'foo',
+ data: this.data,
+ arch: '<tree editable="bottom"><field name="foo"/><field name="int_field"/></tree>',
+ });
+
+ assert.ok(list.$('.o_data_row:first td:nth(1)').hasClass('o_readonly'),
+ "foo field cells should have class 'o_readonly'");
+
+ // edit the first row
+ list.$('.o_data_row:first td:nth(1)').click();
+ assert.ok(list.$('.o_data_row:first').hasClass('o_selected_row'),
+ "first row should be selected");
+ assert.ok(list.$('.o_data_row:first td:nth(1)').hasClass('o_readonly'),
+ "foo field cells should have class 'o_readonly'");
+ assert.strictEqual(list.$('.o_data_row:first td:nth(1)').text(), 'yop',
+ "no widget should be rendered for readonly fields");
+ assert.ok(list.$('.o_data_row:first td:nth(2)').hasClass('o_edit_mode'),
+ "field 'int_field' should be in edition");
+ assert.strictEqual(list.$('.o_data_row:first td:nth(2) input').length, 1,
+ "a widget for field 'int_field should have been rendered'");
+
+ // click again on readonly cell of first line: nothing should have changed
+ list.$('.o_data_row:first td:nth(1)').click();
+ assert.ok(list.$('.o_data_row:first').hasClass('o_selected_row'),
+ "first row should be selected");
+ assert.strictEqual(list.$('.o_data_row:first td:nth(2) input').length, 1,
+ "a widget for field 'int_field' should have been rendered (only once)");
+
+ list.destroy();
+ });
});
});