sergiodlopes / jquery-flexdatalist

Flexible input autocomplete/datalist plugin for jQuery
http://projects.sergiodinislopes.pt/flexdatalist/
MIT License
365 stars 84 forks source link

TAB key management #87

Open Cariocar opened 7 years ago

Cariocar commented 7 years ago

Hi, I'm a new user of your plugin and it's very usefull.

Currently, tab key is mapped to close the search without doing anything. Is it possible to include a parameter which allow us to map an action ? In most of selectbox, when you press tab key, the input content is set to the selected value and the focus is set to the next item without submitting. I think it's a more natural user experience. I try to do it by adding a event trigger, but first time I press tab, it's work. And after, I could not able to reload flexdatalist results without reloading the webpage.

Regards Christophe

DarthSonic commented 5 years ago

I've modifed the code to set the input content to the selected value on pressing tab:

            .on('input keydown', function (event) {
                if (_this.keyNum(event) === 9) {
                    val = $alias[0].value;
                    if (val.length === 0)
                        _this.results.remove();
                }
                _this.action.keypressValue(event, 188);
                _this.action.backSpaceKeyRemove(event);

and (I do not know if needed):

            // Enter/tab key
            if (keynum === 13 || keynum === 9) {
                event.preventDefault();
                $active.click();