this._searchInput = $(searchInput).keyup($.proxy(this._keyUp, this)).keydown($.proxy(function(event) {
// block form submit
if (event.which === 13) {
- // ... unless there are no suggestions
- if (this._itemCount) {
+ // ... unless there are no suggestions or suggestions are optional and none is selected
+ if (this._itemCount && this._itemIndex !== -1) {
event.preventDefault();
}
}
* @param object event
*/
_keyDown: function(event) {
- if (event.which === 13) {
+ if (event.which === 13 && this._itemIndex !== -1) {
event.preventDefault();
}
},
WCF.CloseOverlayHandler.addCallback('WCF.Search.Base', $.proxy(function() { this._clearList(); }, this));
- if (!WCF.Dropdown.getDropdownMenu(this._searchInput.parents('.dropdown').wcfIdentify()).hasClass('dropdownOpen')) {
- WCF.Dropdown.toggleDropdown(this._searchInput.parents('.dropdown').wcfIdentify());
+ var $containerID = this._searchInput.parents('.dropdown').wcfIdentify();
+ if (!WCF.Dropdown.getDropdownMenu($containerID).hasClass('dropdownOpen')) {
+ WCF.Dropdown.toggleDropdown($containerID);
}
// pre-select first item
this._itemIndex = -1;
- this._selectNextItem();
+ if (!WCF.Dropdown.getDropdown($containerID).data('disableAutoFocus')) {
+ this._selectNextItem();
+ }
},
/**