diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js index c95325dbb87..47ce8ad3780 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -861,12 +861,15 @@ var BasicModel = AbstractModel.extend({ var self = this; var onchange_spec = this._buildOnchangeSpecs(record); var idList = record.data.id ? [record.data.id] : []; - var context = this._getContext(record); - var currentData = this._generateOnChangeData(record); - + var options = {}; if (fields.length === 1) { fields = fields[0]; + // if only one field changed, add its context to the RPC context + options.fieldName = fields; } + var context = this._getContext(record, options); + var currentData = this._generateOnChangeData(record); + return self._rpc({ model: record.model, method: 'onchange', diff --git a/addons/web/static/test/views/form_tests.js b/addons/web/static/test/views/form_tests.js index be016ef2285..4bc4e73a5a6 100644 --- a/addons/web/static/test/views/form_tests.js +++ b/addons/web/static/test/views/form_tests.js @@ -2507,6 +2507,40 @@ QUnit.module('Views', { form.destroy(); }); + QUnit.test('context of onchanges contains the context of changed fields', function (assert) { + assert.expect(2); + + this.data.partner.onchanges = { + foo: function () {}, + }; + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '
' + + '' + + '' + + '' + + '' + + '
', + mockRPC: function (route, args) { + if (args.method === 'onchange') { + assert.strictEqual(args.args[4].test, 1, + "the context of the field triggering the onchange should be given"); + assert.strictEqual(args.args[4].int_ctx, undefined, + "the context of other fields should not be given"); + } + return this._super.apply(this, arguments); + }, + res_id: 2, + }); + + form.$buttons.find('.o_form_button_edit').click(); + form.$('.o_form_input:first').val('coucou').trigger('input'); + + form.destroy(); + }); + QUnit.test('navigation with tab key in form view', function (assert) { assert.expect(2);