[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.
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user