diff options
| author | Géry Debongnie <ged@odoo.com> | 2017-04-22 23:29:30 +0200 |
|---|---|---|
| committer | Géry Debongnie <ged@odoo.com> | 2017-04-24 10:19:18 +0200 |
| commit | e4bf1f1ccc522f1715dba82940d5bb647e5138e3 (patch) | |
| tree | 875555672a866da1abc89e736a215768f8270f7f /addons/web/static/src/js/fields | |
| parent | d8261d1162086e5c299e9ee364b7ac0476ea6fee (diff) | |
[FIX] web: form view should focus fields if possible
When a form view switches to edit mode, it is supposed to give the focus
to the first field, or, to a field tagged 'default_focus'.
Diffstat (limited to 'addons/web/static/src/js/fields')
| -rw-r--r-- | addons/web/static/src/js/fields/abstract_field.js | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/addons/web/static/src/js/fields/abstract_field.js b/addons/web/static/src/js/fields/abstract_field.js index d2a317bd3b2..87b3bf3f512 100644 --- a/addons/web/static/src/js/fields/abstract_field.js +++ b/addons/web/static/src/js/fields/abstract_field.js @@ -161,17 +161,24 @@ var AbstractField = Widget.extend({ /** * Activates the field widget. By default, activation means focusing and - * selecting the associated focusable element. + * selecting (if possible) the associated focusable element. The selecting + * part can be disabled. In that case, note that the focused input/textarea + * will have the cursor at the very end. * + * @param {boolean} [noselect=false] if false and the input is of type text + * or textarea, the content will also be selected * @returns {boolean} true if the widget was activated, false if the * focusable element was not found or invisible */ - activate: function () { + activate: function (noselect) { var $focusable = this.getFocusableElement(); if ($focusable.length && $focusable.is(':visible')) { $focusable.focus(); if ($focusable.is('input[type="text"], textarea')) { - setTimeout($focusable.select.bind($focusable), 0); + $focusable[0].selectionStart = $focusable[0].selectionEnd = $focusable[0].value.length; + if (!noselect) { + setTimeout($focusable.select.bind($focusable), 0); + } } return true; } |
