diff options
| author | Aaron Bohy <aab@odoo.com> | 2017-04-06 13:50:05 +0200 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-04-11 19:44:38 +0200 |
| commit | 318ff5f00d288f2e5db49548cd5f86646d22edc4 (patch) | |
| tree | 0d8950887472bd410324ea38fab399aec47d4d94 | |
| parent | 3dfa2caa3d455415d09a7e3051a0f5c1294ca5c1 (diff) | |
[FIX] web: pass context of changed field to onchange RPC
When a field with an onchange is changed, if there is a context
defined on the field in the arch, this context must be added to
the context sent with the onchange RPC.
| -rw-r--r-- | addons/web/static/src/js/views/basic/basic_model.js | 9 | ||||
| -rw-r--r-- | addons/web/static/test/views/form_tests.js | 34 |
2 files changed, 40 insertions, 3 deletions
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: '<form>' + + '<group>' + + '<field name="foo" context="{\'test\': 1}"/>' + + '<field name="int_field" context="{\'int_ctx\': 1}"/>' + + '</group>' + + '</form>', + 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); |
