harvesthq / chosen

Deprecated - Chosen is a library for making long, unwieldy select boxes more friendly.
http://harvesthq.github.io/chosen/
Other
21.85k stars 4.1k forks source link

dropdown is opening for every keypress #2245

Open risperdal opened 9 years ago

risperdal commented 9 years ago

I dont know if this done on purpose but in my form the f2 key is triggering filter function.

When user selects some item on dropdown and presses f2 key, it is filtering the form but the dropdown is opening.

The dropdown shouldnt toggled for every keypress.

the fix

 AbstractChosen.prototype.keyup_checker = function(evt) {
            var stroke, _ref;
            stroke = (_ref = evt.which) != null ? _ref : evt.keyCode;
            this.search_field_scale();
            switch (stroke) {
                case 8:
                    if (this.is_multiple && this.backstroke_length < 1 && this.choices_count() > 0) {
                        return this.keydown_backstroke();
                    } else if (!this.pending_backstroke) {
                        this.result_clear_highlight();
                        return this.results_search();
                    }
                    break;
                case 13:
                    evt.preventDefault();
                    if (this.results_showing) {
                        return this.result_select(evt);
                    }
                    break;
                case 27:
                    if (this.results_showing) {
                        this.results_hide();
                    }
                    return true;
                case 9:
                case 38:
                case 40:
                case 16:
                case 91:
                case 17:
                    break;
                default:
                    //if not showing then do not toggle
                    if (this.results_showing) {
                        return this.results_search();
                    }
            }
        };
tjschuck commented 9 years ago

Some other potentially-unexpected buttons that open Chosen: the option key, and turning off caps lock (weirdly, not turning on caps lock).

braddunbar commented 8 years ago

FYI, I pulled a fix for the option key in #2475. :smiley_cat: