auto-complete icon indicating copy to clipboard operation
auto-complete copied to clipboard

javascript error if arrow-down before typing a value

Open tomschreck opened this issue 7 years ago • 1 comments

Steps to reproduce and a minimal demo

tab into textbox configured to use ngui-auto-complete. Click down arrow instead of typing a value in the textbox. Clicking the down arrow will cause a JavaScript error. See video here:

https://www.screencast.com/t/nvXm4JWQfMe

the error starts in auto-complete.component.js around line 45:


            switch (evt.keyCode) {
                case 27:
                    break;
                case 38:
                    _this.itemIndex = (totalNumItem + _this.itemIndex - 1) % totalNumItem;
                    _this.scrollToView(_this.itemIndex);
                    break;
                case 40:
                    _this.dropdownVisible = true;
                    _this.itemIndex = (totalNumItem + _this.itemIndex + 1) % totalNumItem;
                    _this.scrollToView(_this.itemIndex);
                    break;
                case 13:
                    if (_this.filteredList.length > 0) {
                        _this.selectOne(_this.filteredList[_this.itemIndex]);
                    }
                    evt.preventDefault();
                    break;
                case 9:
                    if (_this.tabToSelect && _this.filteredList.length > 0) {
                        _this.selectOne(_this.filteredList[_this.itemIndex]);
                    }
                    break;
            }

the call to _this.scrollToView(_this.itemIndex); is the culprit. _this.itemIndex has a value of NAN.

There are no values yet as the user hasn't typed anything in text box to cause a filter event to happen to produce a list, so totalNumItem is 0 resulting in _this.itemIndex calculated value to be NAN.

tomschreck avatar Jun 22 '17 14:06 tomschreck

This should be closed?

ndcunningham avatar Jan 02 '18 21:01 ndcunningham