Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

5

How to make the enter key work as tab key?

By
tolstoj
on 2/13/13, 11:10 AM 5,815 views

For example in view_list_editable.js:483 by Sale Order creation.

keyup_ENTER: function () {
        return this._next();
    },

Something like what does't worked for me:

$(':input').bind('keypress', function(event) {
    if(event.which === 13) {
        $(this).nextAll(':input').first().focus();
    }
});
6

tolstoj

--tolstoj--
899
| 6 5 8
Germany
--tolstoj--

hi

tolstoj
On 2/18/13, 11:45 AM

I will answer my question myself. If your customer want to use ENTER button as a TAB button in product list of sale order, you must edit view_list_editable.js:483

keyup_ENTER: function () {
    return this._next();
},

and put where something like that:

keyup_ENTER: function (e) {
        var source_field = $(e.target).closest('[data-fieldname]').attr('data-fieldname');
        var fields_order = this.editor.form.fields_order;
        var field_index  = _(fields_order).indexOf(source_field);            
        var fields       = this.editor.form.fields;
        var field;
        do {
            if (++field_index >= fields_order.length) {
                e.preventDefault();
                return this._next();
            }
            field = fields[fields_order[field_index]];
        } while (!field.$el.is(':visible'));
        field.focus();
        return $.when();
    },

it's mainly from keydown_RIGHT func. because it has same logic. It's work's only for text fields. For text-area field you must handle stopPropagation() for ENTER key event in text-area fields in view_form.js

this code is not working......please help..

Rishabh
on 5/28/13, 3:44 AM
0
Sody
On 7/31/14, 10:51 AM

HI,

I would like to block ENTER only on open page, in grid where can user create new position.

How to do this ?

 

0
Benjamin Ujvari-Cseh
On 2/25/14, 6:11 AM

If you don't want to use the "Enter" key, you can use the "+" key from the numpad which is just above.

This is interesting because you keep the default behavior of "Enter" key as long as you don't have "+" character in your field. If you have it, you can use the other "+" key, which doesn't come with the same keycode.

The only problem is when you type with this key: it adds the character '+' on the field. But you can disable this with this code:

    keydown_NUMPAD_ADD: function (e) {
        e.preventDefault();
        return $.when();
    }

In order to have the same behavior of "Tab" key, just use @tolstoj code:

    keyup_NUMPAD_ADD: function (e) {
        var source_field = $(e.target).closest('[data-fieldname]').attr('data-fieldname');
        var fields_order = this.editor.form.fields_order;
        var field_index  = _(fields_order).indexOf(source_field);            
        var fields       = this.editor.form.fields;
        var field;
        do {
            if (++field_index >= fields_order.length) {
                e.preventDefault();
                return this._next();
            }
            field = fields[fields_order[field_index]];
        } while (!field.$el.is(':visible'));
        field.focus();
        return $.when();
    },

With this, if you switch name field with quantity field in sale orders lines in editable mode for example, behavior will be this:

  • Enter product code
  • Type "+" numpad key
  • Enter quantity
  • Type "Enter" numpad key
  • And so on...

It will be even better if you have set pricelist, because you just need to enter product's code and quantity and you can create a new record.

This stays in view_list_editable.js so you don't have to worry with other views behavior.

Best regards, Benjamin

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 2/13/13, 11:10 AM
Seen: 5815 times
Last updated: 7/14/16, 5:07 AM