summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/basic/basic_renderer.js
diff options
context:
space:
mode:
authorVincent Schippefilt <vsc@odoo.com>2018-08-30 16:25:42 +0200
committerVincent Schippefilt <vsc@odoo.com>2018-09-25 16:49:23 +0200
commit48a53f2ea5c5cd225a08b65c90b94e0032c0a776 (patch)
treea44025d5b4350a83a5cb826adcc7e5effe7ac7b3 /addons/web/static/src/js/views/basic/basic_renderer.js
parente343f5f5f95607b91a61fed167a6f11f0eeaeaa8 (diff)
[FIX] web: improve automatic creation of new lines in x2many in forms
This commit fixes a few issues with the previous implementation of the automatic addition of new lines in x2many inside forms 1. Before this commit, when there is a change of mode in a formview `edit` -> `readonly` -> `edit`, there may be some cases that mistakenly and automatically opens a modal. This case occurs in a form view with a x2many field whose 1st inner focusable element opens a modal (e.g. "Add an item"). In `edit` mode: 1. Open this modal from the x2many 2. Close the modal 3. Change mode to `readonly` 4. Change mode to `edit` > the same modal is automatically open. This is due to the tracking of the last activated field that persists after a change of mode. Since the last activated field in the 1st `edit` is the x2many, it is granted the focus at the beginning of the 2nd `edit`, which automatically opens the modal. This commit fixes the issue by resetting the tracking of the last activated field when there is a change of mode. As a result, at the beginning of the 2nd `edit`, the focus should always be on the 1st field. 2. Before this commit, if the focus was moved out of the form (to a modal for instance) then back, the form would re-activate the last field, which is the x2many and would re-add a new line. This behavior is not correct and now going back from a modal to a form does not add a new line. Co-authored-by: Alexandre Kühn <aku@odoo.com>
Diffstat (limited to 'addons/web/static/src/js/views/basic/basic_renderer.js')
-rw-r--r--addons/web/static/src/js/views/basic/basic_renderer.js14
1 files changed, 10 insertions, 4 deletions
diff --git a/addons/web/static/src/js/views/basic/basic_renderer.js b/addons/web/static/src/js/views/basic/basic_renderer.js
index 197892f3361..33267283a15 100644
--- a/addons/web/static/src/js/views/basic/basic_renderer.js
+++ b/addons/web/static/src/js/views/basic/basic_renderer.js
@@ -168,9 +168,10 @@ var BasicRenderer = AbstractRenderer.extend({
* @private
* @param {Object} record
* @param {integer} currentIndex
- * @param {Object} [options]
+ * @param {Object} [options={}]
* @param {integer} [options.inc=1] - the increment to use when searching for the
* "next" possible one
+ * @param {boolean} [options.noAutomaticCreate=false]
* @param {boolean} [options.wrap=false] if true, when we arrive at the end of the
* list of widget, we wrap around and try to activate widgets starting at
* the beginning. Otherwise, we just stop trying and return -1
@@ -184,7 +185,11 @@ var BasicRenderer = AbstractRenderer.extend({
var recordWidgets = this.allFieldWidgets[record.id] || [];
for (var i = 0 ; i < recordWidgets.length ; i++) {
- var activated = recordWidgets[currentIndex].activate({event: options.event});
+ var activated = recordWidgets[currentIndex].activate(
+ {
+ event: options.event,
+ noAutomaticCreate: options.noAutomaticCreate || false
+ });
if (activated) {
return currentIndex;
}
@@ -213,11 +218,12 @@ var BasicRenderer = AbstractRenderer.extend({
* @private
* @param {Object} record
* @param {integer} currentIndex
+ * @param {Object|undefined} options
* @return {integer}
*/
- _activateNextFieldWidget: function (record, currentIndex) {
+ _activateNextFieldWidget: function (record, currentIndex, options) {
currentIndex = (currentIndex + 1) % (this.allFieldWidgets[record.id] || []).length;
- return this._activateFieldWidget(record, currentIndex, {inc: 1});
+ return this._activateFieldWidget(record, currentIndex, _.extend({inc: 1}, options));
},
/**
* This is a wrapper of the {@see _activateFieldWidget} function to select