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 b786673ec7c..42da94f7166 100644 --- a/addons/web/static/src/js/views/list/list_controller.js +++ b/addons/web/static/src/js/views/list/list_controller.js @@ -61,10 +61,6 @@ var ListController = BasicController.extend({ session.user_has_group('base.group_allow_export').then(has_group => { this.isExportEnable = has_group; }); - Object.defineProperty(this, 'mode', { - get: () => this.renderer.isEditable() ? 'edit' : 'readonly', - set: () => {}, - }); }, //-------------------------------------------------------------------------- @@ -519,6 +515,7 @@ var ListController = BasicController.extend({ */ _setMode: function (mode, recordID) { if ((recordID || this.handle) !== this.handle) { + this.mode = mode; this.updateButtons(mode); return this.renderer.setRowMode(recordID, mode); } else { diff --git a/addons/web/static/src/js/views/list/list_view.js b/addons/web/static/src/js/views/list/list_view.js index 5845375fd70..abe05173bc8 100644 --- a/addons/web/static/src/js/views/list/list_view.js +++ b/addons/web/static/src/js/views/list/list_view.js @@ -60,7 +60,7 @@ var ListView = BasicView.extend({ this.controllerParams.editable = editable; this.controllerParams.hasActionMenus = params.hasActionMenus; this.controllerParams.toolbarActions = viewInfo.toolbar; - this.controllerParams.mode = editable ? 'edit' : 'readonly'; + this.controllerParams.mode = 'readonly'; this.controllerParams.selectedRecords = selectedRecords; this.rendererParams.arch = this.arch; diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js index 703218a071a..1e2357b1eb3 100644 --- a/addons/web/static/tests/views/list_tests.js +++ b/addons/web/static/tests/views/list_tests.js @@ -1229,6 +1229,52 @@ QUnit.module('Views', { form.destroy(); }); + QUnit.test('edit field in editable field without editing the row', async function (assert) { + // some widgets are editable in readonly (e.g. priority, boolean_toggle...) and they + // thus don't require the row to be switched in edition to be edited + assert.expect(13); + + const list = await createView({ + View: ListView, + model: 'foo', + data: this.data, + arch: ` + + + + `, + mockRPC(route, args) { + if (args.method === 'write') { + assert.step('write: ' + args.args[1].bar); + } + return this._super(...arguments); + }, + }); + + // toggle the boolean value of the first row without editing the row + assert.ok(list.$('.o_data_row:first .o_boolean_toggle input')[0].checked); + assert.containsNone(list, '.o_selected_row'); + await testUtils.dom.click(list.$('.o_data_row:first .o_boolean_toggle')); + assert.notOk(list.$('.o_data_row:first .o_boolean_toggle input')[0].checked); + assert.containsNone(list, '.o_selected_row'); + assert.verifySteps(['write: false']); + + // toggle the boolean value after switching the row in edition + assert.containsNone(list, '.o_selected_row'); + await testUtils.dom.click(list.$('.o_data_row .o_data_cell:first')); + assert.containsOnce(list, '.o_selected_row'); + await testUtils.dom.click(list.$('.o_selected_row .o_boolean_toggle')); + assert.containsOnce(list, '.o_selected_row'); + assert.verifySteps([]); + + // save + await testUtils.dom.click(list.$('.o_list_button_save')); + assert.containsNone(list, '.o_selected_row'); + assert.verifySteps(['write: true']); + + list.destroy(); + }); + QUnit.test('basic operations for editable list renderer', async function (assert) { assert.expect(2);