[FIX] web: unselect current row on one2many before doing something else
In a one2many, when we click on 'Add an item', we need to unselect the current row. Otherwise, its changes will not be committed and it will be in practice discarded.
This commit is contained in:
committed by
Aaron Bohy
parent
7056ec1ac6
commit
3662c7246f
@@ -167,7 +167,7 @@ var BasicModel = AbstractModel.extend({
|
||||
};
|
||||
return this._makeDefaultRecord(list.model, params).then(function (id) {
|
||||
list.count++;
|
||||
list._changes = list.data.slice(0);
|
||||
list._changes = list._changes || list.data.slice(0);
|
||||
if (position === 'top') {
|
||||
list._changes.unshift(id);
|
||||
} else {
|
||||
|
||||
@@ -485,10 +485,14 @@ ListRenderer.include({
|
||||
_onAddRecord: function (event) {
|
||||
// we don't want the browser to navigate to a the # url
|
||||
event.preventDefault();
|
||||
|
||||
// we don't want the click to cause other effects, such as unselecting
|
||||
// the row that we are creating, because it counts as a click on a tr
|
||||
event.stopPropagation();
|
||||
|
||||
// but we do want to unselect current row
|
||||
this._unselectRow();
|
||||
|
||||
this.trigger_up('add_record');
|
||||
},
|
||||
/**
|
||||
|
||||
@@ -1177,6 +1177,57 @@ QUnit.module('relational_fields', {
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('one2many list (editable): edition, part 2', function (assert) {
|
||||
assert.expect(8);
|
||||
|
||||
var form = createView({
|
||||
View: FormView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<form string="Partners">' +
|
||||
'<field name="p">' +
|
||||
'<tree editable="top">' +
|
||||
'<field name="foo"/>' +
|
||||
'</tree>' +
|
||||
'</field>' +
|
||||
'</form>',
|
||||
res_id: 1,
|
||||
mockRPC: function (route, args) {
|
||||
if (args.method === 'write') {
|
||||
assert.strictEqual(args.args[1].p[0][0], 0,
|
||||
"should send a 0 command for field p");
|
||||
assert.strictEqual(args.args[1].p[1][0], 0,
|
||||
"should send a second 0 command for field p");
|
||||
}
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
});
|
||||
|
||||
// edit mode, then click on Add an item and enter a value
|
||||
form.$buttons.find('.o_form_button_edit').click();
|
||||
form.$('.o_form_field_x2many_list_row_add a').click();
|
||||
form.$('td.o_edit_mode input').val('kartoffel').trigger('input');
|
||||
|
||||
// click again on Add an item
|
||||
form.$('.o_form_field_x2many_list_row_add a').click();
|
||||
assert.strictEqual(form.$('td:contains(kartoffel)').length, 1,
|
||||
"should have one td with the new value");
|
||||
assert.strictEqual(form.$('td.o_edit_mode input').length, 1,
|
||||
"should have one other new td");
|
||||
assert.strictEqual(form.$('tr.o_data_row').length, 2, "should have 2 data rows");
|
||||
|
||||
// enter another value and save
|
||||
form.$('td.o_edit_mode input').val('gemuse').trigger('input');
|
||||
form.$buttons.find('.o_form_button_save').click();
|
||||
assert.strictEqual(form.$('tr.o_data_row').length, 2, "should have 2 data rows");
|
||||
assert.strictEqual(form.$('td:contains(kartoffel)').length, 1,
|
||||
"should have one td with the new value");
|
||||
assert.strictEqual(form.$('td:contains(gemuse)').length, 1,
|
||||
"should have one td with the new value");
|
||||
|
||||
form.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('onchange in a one2many', function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user