From 4586b876f273181b57f3f3fe4b0dce2a2d26b27a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Wed, 14 Mar 2018 10:51:30 +0100 Subject: [FIX] web: unselect current row before changing page The issue here is quite simple. If we are editing a multipage one2many field, then we click on the pager, we need to properly unselect the current row. If we do not do that, then we can enter invalid data. For example, assume that there is a readonly field. We click on add, it creates a (virtual) record with no value for that field. When we click on the pager, we select the next page, and bypass all validation. --- .../static/tests/fields/relational_fields_tests.js | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) (limited to 'addons/web/static/tests/fields/relational_fields_tests.js') diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js index 5891c5d1515..8aeca04a509 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -4361,6 +4361,83 @@ QUnit.module('relational_fields', { form.destroy(); }); + QUnit.test('editable one2many list, required field and pager', function (assert) { + assert.expect(1); + + this.data.turtle.records.push({id:4, turtle_foo: 'stephen hawking'}); + this.data.turtle.fields.turtle_foo.required = true; + this.data.partner.records[0].turtles = [1,2,3,4]; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '
' + + '' + + '' + + '' + + '' + + '' + + '
', + res_id: 1, + }); + + // add a (empty) record + form.$buttons.find('.o_form_button_edit').click(); + form.$('.o_field_x2many_list_row_add a').click(); + + // go on next page. The new record is not valid and should be discarded + form.$('.o_pager_next').click(); + assert.strictEqual(form.$('tr.o_data_row').length, 1, + "should have 1 data rows"); + + form.destroy(); + }); + + QUnit.test('editable one2many list, required field, pager and confirm discard', function (assert) { + assert.expect(3); + + this.data.turtle.records.push({id:4, turtle_foo: 'stephen hawking'}); + this.data.turtle.fields.turtle_foo.required = true; + this.data.partner.records[0].turtles = [1,2,3,4]; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '
' + + '' + + '' + + '' + + '' + + '' + + '' + + '
', + res_id: 1, + }); + + // add a record with a dirty state, but not valid + form.$buttons.find('.o_form_button_edit').click(); + form.$('.o_field_x2many_list_row_add a').click(); + form.$('input[name="turtle_int"]').val(4321).trigger('input'); + + // go to next page. The new record is not valid, but dirty. we should + // see a confirm dialog + form.$('.o_pager_next').click(); + + assert.strictEqual(form.$('.o_cp_pager').text().trim(), '1-3 / 4', + "pager should still display the correct total"); + + // click on cancel + $('.modal .modal-footer .btn-default').click(); // click on cancel + + assert.strictEqual(form.$('.o_cp_pager').text().trim(), '1-3 / 4', + "pager should again display the correct total"); + assert.strictEqual(form.$('.o_field_one2many input.o_field_invalid').length, 1, + "there should be an invalid input in the one2many"); + form.destroy(); + }); + QUnit.test('unselecting a line with missing required data', function (assert) { assert.expect(5); -- cgit v1.2.3