diff options
| author | Aaron Bohy <aab@odoo.com> | 2018-09-13 16:09:33 +0200 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2018-09-17 13:32:37 +0200 |
| commit | 4393e48fec93d2f0872f48bc4ad172b03c948c24 (patch) | |
| tree | 37de1118bff7c01abb49404dd53376258eee903b /addons/web/static/src/js/fields | |
| parent | 0354579c986d63b08eb85571602097c49afd1678 (diff) | |
[FIX] web: navigate in editable list with custom controls
Rev. f241441 recently added the possibiliy to define custom
controls (instead of the single 'Add a line') in editable list
views. However, it didn't take into account keyboard navigation.
Suppose that the focus is on the field preceeding the list, and
the user clicks on TAB, the code assumed that there was only one
control, and focused it. However, when there were several control,
the last one was focused (which is typically the less common one),
and there was no way to navigate to the others.
This rev. focuses the first control by default, and allows to
navigate through controls with RIGHT and LEFT. Pressing TAB still
moves out of the list, to the next field.
Note that i'm not happy with this fix, as the logic doesn't seem
to be in the right place. Indeed, the notion of controls is the
concern of the editable list, not the x2many field, so the list
should handle this logic by itself. Unfortenately, this is not that
easy to change, as for now the list doesn't even know that we are
navigating to/from its control(s), until we click on it/them.
Changing that will be for later, in master.
We also did a linting pass on the concerned code.
Task 1878254
Diffstat (limited to 'addons/web/static/src/js/fields')
| -rw-r--r-- | addons/web/static/src/js/fields/relational_fields.js | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index cf217cf70bc..4c92c0973b9 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -402,7 +402,7 @@ var FieldMany2One = AbstractField.extend({ var domain = this.record.getDomain(this.recordParams); // Add the additionalContext - _.extend(context, this.additionalContext) + _.extend(context, this.additionalContext); var blacklisted_ids = this._getSearchBlacklist(); if (blacklisted_ids.length > 0) { @@ -848,9 +848,8 @@ var FieldX2Many = AbstractField.extend({ /** * @override - * @param {Object} [options] */ - activate: function (options) { + activate: function () { if (!this.activeActions.create || this.isReadonly || !this.$el.is(":visible")) { return false; } @@ -858,7 +857,7 @@ var FieldX2Many = AbstractField.extend({ this.$buttons.find(".o-kanban-button-new").focus(); } if (this.view.arch.tag === 'tree') { - this.renderer.$('.o_field_x2many_list_row_add a').focus(); + this.renderer.$('.o_field_x2many_list_row_add a:first').focus(); } return true; }, @@ -1166,6 +1165,31 @@ var FieldX2Many = AbstractField.extend({ } }, /** + * Override to handle the navigation inside editable list controls + * + * @override + * @private + */ + _onNavigationMove: function (ev) { + if (this.view.arch.tag === 'tree') { + var $curControl = this.renderer.$('.o_field_x2many_list_row_add a:focus'); + if ($curControl.length) { + var $nextControl; + if (ev.data.direction === 'right') { + $nextControl = $curControl.next('a'); + } else if (ev.data.direction === 'left') { + $nextControl = $curControl.prev('a'); + } + if ($nextControl && $nextControl.length) { + ev.stopPropagation(); + $nextControl.focus(); + return; + } + } + } + this._super.apply(this, arguments); + }, + /** * Called when the user clicks on a relational record. * * @abstract @@ -1660,7 +1684,7 @@ var FieldMany2ManyBinaryMultiFiles = AbstractField.extend({ var attachment_ids = this.value.res_ids; // Don't create an attachment if the upload window is cancelled. - if(files.length == 0) + if(files.length === 0) return; _.each(files, function (file) { |
