views:

142

answers:

1

I am trying to make a auto complete box using ruby on rails, jquery and a plugin that combines the two called jrails_auto_complete. It works fine in FF but in safari 4 the keyboard select doesn't work. I would love to try and fix this for my application but cannot seem to do it. I don't know much java script, maybe someone can help. Is there any known issues with key actions in safari 4?

The plugin has keyboard code:

onKeyPress: function(e) {
            var autocomplete = this;

            if (this.active) {
                switch (e.keyCode) {
                    case 9:     // tab
                    case 13:    // return
                        this.selectEntry();
                        stopEvent(e);
                    case 27:    // esc
                        this.hide();
                        this.active = false;
                        stopEvent(e);
                    case 37:    // left
                    case 39:    // right
                        return;
                    case 38:    // up
                        this.markPrevious();
                        this.render();
                        stopEvent(e);
                        return;
                    case 40:    // down
                        this.markNext();
                        this.render();
                        stopEvent(e);
                        return;
                }
            }

I did a little debugging and found that certain keys including the letter keys and the return key will call this function... I dont know why some wouldn't be picked up by onKeyPress.

Thanks

+2  A: 

Use the keydown event, not keypress, to detect non-character keys. This has always been the case, but Safari slightly differs from other browsers in the keys it sends.

Explanation.

bobince