From 1c59de867dd04ae7aa2b6625d4f1c5c877b7586f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Tue, 28 Aug 2018 11:58:52 +0200 Subject: [PATCH] [FIX] web: prevent handle from crashing with text field 289adeb63f51a9af26b8f383ba80089aa7aa6d87 introduced a bug where we tried to trigger an event on an element that didn't exist. Indeed there is no input if it's not in edit mode. This commit fixes it. PR: none Task: none --- addons/web/static/src/js/fields/basic_fields.js | 4 +++- addons/web/static/tests/fields/relational_fields_tests.js | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index ed393d667b7..00a4532c2e1 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -1079,7 +1079,9 @@ var FieldText = InputField.extend(TranslatableFieldMixin, { reset: function () { var self = this; return $.when(this._super.apply(this, arguments)).then(function () { - self.$input.trigger('change'); + if (self.mode === 'edit') { + self.$input.trigger('change'); + } }); }, //-------------------------------------------------------------------------- diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js index 15499234c49..e5a0ad43a70 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -9491,7 +9491,7 @@ QUnit.module('relational_fields', { form.destroy(); }); - QUnit.test('one2many with sequence field, fetch name_get from empty list', function (assert) { + QUnit.test('one2many with sequence field, fetch name_get from empty list, field text', function (assert) { // There was a bug where a RPC would fail because no route was set. // The scenario is: // - create a new parent model, which has a one2many @@ -9501,6 +9501,11 @@ QUnit.module('relational_fields', { // - reorder the lines with the handle // -> This will call a resequence, which calls a name_get. // -> With the bug that would fail, if it's ok the test will pass. + + // This test will also make sure lists with + // FieldText (turtle_description) can be reordered with a handle. + // More specifically this will trigger a reset on a FieldText + // while the field is not in editable mode. assert.expect(4); this.data.turtle.fields.turtle_int.default = 10; @@ -9521,6 +9526,7 @@ QUnit.module('relational_fields', { '' + '' + '' + + '' + '' + '' + '',