summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorGéry Debongnie <ged@odoo.com>2017-03-30 22:03:29 +0200
committerAaron Bohy <aab@odoo.com>2017-04-11 19:44:38 +0200
commitb889e4b3e6d531ccb0e8f4107b50f1131e65e528 (patch)
tree38cbd455ec2112fb7be2dd01cf441e8db48b4145 /addons/web/static/src
parent11a17f7bb994bcc56b7a20ae9e91ca927adb52ed (diff)
[IMP] web: form support for tab navigation
The new form view does not really work well with the TAB key. This is partly caused by the fact that the tab event is preventdefaulted. With this commit, we reintroduce a basic navigation with TAB and shift+TAB.
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/fields/abstract_field.js2
-rw-r--r--addons/web/static/src/js/views/form/form_renderer.js38
2 files changed, 39 insertions, 1 deletions
diff --git a/addons/web/static/src/js/fields/abstract_field.js b/addons/web/static/src/js/fields/abstract_field.js
index e4f5ef9d9f8..01de5fb334c 100644
--- a/addons/web/static/src/js/fields/abstract_field.js
+++ b/addons/web/static/src/js/fields/abstract_field.js
@@ -348,7 +348,7 @@ var AbstractField = Widget.extend({
*/
_onKeydown: function (event) {
if (event.which === $.ui.keyCode.TAB) {
- this.trigger_up('move_next');
+ this.trigger_up(event.shiftKey ? 'move_previous' : 'move_next');
event.preventDefault();
}
},
diff --git a/addons/web/static/src/js/views/form/form_renderer.js b/addons/web/static/src/js/views/form/form_renderer.js
index 2370b1af19a..751923c3b9f 100644
--- a/addons/web/static/src/js/views/form/form_renderer.js
+++ b/addons/web/static/src/js/views/form/form_renderer.js
@@ -15,6 +15,10 @@ var FIELD_CLASSES = {
return BasicRenderer.extend({
className: "o_form_view",
+ custom_events: {
+ move_next: '_onMoveNext',
+ move_previous: '_onMovePrevious',
+ },
/**
* @override method from BasicRenderer
* @param {Object} params
@@ -716,6 +720,40 @@ return BasicRenderer.extend({
});
},
+
+ //--------------------------------------------------------------------------
+ // Handlers
+ //--------------------------------------------------------------------------
+
+ /**
+ * When someone presses TAB in a widget, it is nice to be able to go to the
+ * next widget, especially since the TAB key event is preventDefaulted
+ *
+ * @private
+ * @param {OdooEvent} event
+ */
+ _onMoveNext: function (event) {
+ event.stopPropagation();
+ var index = this.widgets.indexOf(event.target);
+ if (index + 1 < this.widgets.length) {
+ this.widgets[index + 1].activate();
+ }
+ },
+ /**
+ * When someone presses SHIFT+TAB in a widget, it is nice to be able to go
+ * back to the previous widget, especially since the TAB key event is
+ * preventDefaulted
+ *
+ * @private
+ * @param {OdooEvent} event
+ */
+ _onMovePrevious: function (event) {
+ event.stopPropagation();
+ var index = this.widgets.indexOf(event.target);
+ if (index >= 1) {
+ this.widgets[index - 1].activate();
+ }
+ },
});
});