diff options
| author | Martin Geubelle <mge@odoo.com> | 2017-11-02 16:00:58 +0100 |
|---|---|---|
| committer | Martin Geubelle <mge@odoo.com> | 2017-11-07 14:12:18 +0100 |
| commit | 255478acbd66f01daf32422636f09f2014ebc9f8 (patch) | |
| tree | 32603470881197cd67f85efdee8aa37dbd173a18 /addons/web/static/src/js | |
| parent | f8bf66b6def30b5738d91da564fda0a8eb8eeead (diff) | |
[FIX] web: clear m2o input at creation cancel
After entering a value in a many2one, if one clicks somewhere else, a popup
is opened to suggest the user to create (or not) a new record with the entered
value.
Before this rev, closing this popup resulted in an unclear situation where the
input was still set with the entered value but the new record hadn't been created.
This commit fixes this by clearing the input value if the record is not created.
See task#36055
Diffstat (limited to 'addons/web/static/src/js')
| -rw-r--r-- | addons/web/static/src/js/fields/relational_fields.js | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index d7b4368036d..19f2728a3ae 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -46,7 +46,7 @@ var M2ODialog = Dialog.extend({ click: function () { if (this.$("input").val() !== ''){ this.trigger_up('quick_create', { value: this.$('input').val() }); - this.close(); + this.close(true); } else { this.$("input").focus(); } @@ -71,12 +71,30 @@ var M2ODialog = Dialog.extend({ this.$("p").text(_.str.sprintf(_t("You are creating a new %s, are you sure it does not exist yet?"), this.name)); this.$("input").val(this.value); }, + /** + * @override + * @param {boolean} isSet + */ + close: function (isSet) { + this.isSet = isSet; + this._super.apply(this, arguments); + }, + /** + * @override + */ + destroy: function () { + if (!this.isSet) { + this.trigger_up('closed_unset'); + } + this._super.apply(this, arguments); + }, }); var FieldMany2One = AbstractField.extend({ supportedFieldTypes: ['many2one'], template: 'FieldMany2One', custom_events: _.extend({}, AbstractField.prototype.custom_events, { + 'closed_unset': '_onDialogClosedUnset', 'quick_create': '_onQuickCreate', 'search_create_popup': '_onSearchCreatePopup', }), @@ -450,6 +468,16 @@ var FieldMany2One = AbstractField.extend({ }); } }, + + /** + * Reset the input as dialog has been closed without m2o creation. + * + * @private + */ + _onDialogClosedUnset: function () { + this.floating = false; + this._render(); + }, /** * @private */ |
