Improved WCF.Search.Base/WCF.EditableItemList
authorAlexander Ebert <ebert@woltlab.com>
Tue, 30 Jul 2013 13:23:17 +0000 (15:23 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 30 Jul 2013 13:23:17 +0000 (15:23 +0200)
wcfsetup/install/files/js/WCF.js

index ef2a14de27cbb20f2335632a4657394cd6bb1a76..635913168614e494f3e54f113df7b080088f8e0a 100755 (executable)
@@ -5315,11 +5315,15 @@ WCF.Search.Base = Class.extend({
         * @param       object          event
         */
        _keyDown: function(event) {
-               if (event.which === 13) {
-                       if (this._searchInput.parents('.dropdown').data('disableAutoFocus') && this._itemIndex === -1) {
-                               // allow submitting
+               if (event.which === $.ui.keyCode.ENTER) {
+                       var $dropdown = this._searchInput.parents('.dropdown');
+                       
+                       if ($dropdown.data('disableAutoFocus')) {
+                               if (this._itemIndex !== -1) {
+                                       event.preventDefault();
+                               }
                        }
-                       else {
+                       else if ($dropdown.data('preventSubmit') || this._itemIndex !== -1) {
                                event.preventDefault();
                        }
                }
@@ -7639,6 +7643,9 @@ WCF.EditableItemList = Class.extend({
                                setTimeout(function() { self._onPaste(); }, 100);
                        });
                }
+               
+               // block form submit through [ENTER]
+               this._searchInput.parents('.dropdown').data('preventSubmit', true);
        },
        
        /**
@@ -7648,7 +7655,13 @@ WCF.EditableItemList = Class.extend({
         */
        _keyDown: function(event) {
                // 188 = [,]
-               if (event === null || event.which === 188) {
+               if (event === null || event.which === 188 || event.which === $.ui.keyCode.ENTER) {
+                       if (event.which === $.ui.keyCode.ENTER && this._search) {
+                               if (this._search._itemIndex !== -1) {
+                                       return false;
+                               }
+                       }
+                       
                        var $value = $.trim(this._searchInput.val());
                        
                        // read everything left from caret position