This question has been flagged
4 Replies
29586 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();
    }
});
Avatar
Discard
Author Best Answer

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

Avatar
Discard

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

Best Answer

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

Avatar
Discard
Best Answer

HI,

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

How to do this ?

 

Avatar
Discard