WCF.Search.Base now supports standalone calls
authorAlexander Ebert <ebert@woltlab.com>
Mon, 13 Aug 2012 13:06:13 +0000 (15:06 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 13 Aug 2012 13:06:13 +0000 (15:06 +0200)
A callback is no longer necessary, by default the value is just auto-completed. Furthermore we're suppressing the browsers default auto-complete, as it collides with the suggestion itself.

wcfsetup/install/files/acp/templates/userSearch.tpl
wcfsetup/install/files/js/WCF.js

index b2ada61065162de48aa337db93d39ce42ca47a51..cf05441babc0df494e1e1cde0d827a718b023990 100644 (file)
@@ -4,6 +4,7 @@
        //<![CDATA[
        $(function() {
                WCF.TabMenu.init();
+               new WCF.Search.User('#username');
        });
        //]]>
 </script>
                                <dt><label for="username">{lang}wcf.user.username{/lang}</label></dt>
                                <dd>
                                        <input type="text" id="username" name="username" value="{$username}" class="medium" />
-                                       <script type="text/javascript">
-                                               //<![CDATA[
-                                               var suggestion = new Suggestion('username');
-                                               suggestion.enableMultiple(false);
-                                               //]]>
-                                       </script>
                                </dd>
                        </dl>
                        
index d96096000e7c03e49b0446cdc201fefe0f6de618..4ae278cb58f013946734578acc184b8b26e62dbb 100755 (executable)
@@ -4005,12 +4005,12 @@ WCF.Search.Base = Class.extend({
         * @param       boolean         commaSeperated
         */
        init: function(searchInput, callback, excludedSearchValues, commaSeperated) {
-               if ((callback === null && !commaSeperated) && !$.isFunction(callback)) {
+               if (callback !== null && callback !== undefined && !$.isFunction(callback)) {
                        console.debug("[WCF.Search.Base] The given callback is invalid, aborting.");
                        return;
                }
-
-               this._callback = callback;
+               
+               this._callback = (callback) ? callback : null;
                this._excludedSearchValues = [];
                if (excludedSearchValues) {
                        this._excludedSearchValues = excludedSearchValues;
@@ -4024,6 +4024,10 @@ WCF.Search.Base = Class.extend({
                this._proxy = new WCF.Action.Proxy({
                        success: $.proxy(this._success, this)
                });
+               
+               if (this._searchInput.getTagName() === 'input') {
+                       this._searchInput.attr('autocomplete', 'off');
+               }
        },
        
        /**
@@ -4153,6 +4157,7 @@ WCF.Search.Base = Class.extend({
         * @param       object          event
         */
        _executeCallback: function(event) {
+               var $clearSearchInput = false;
                var $listItem = $(event.currentTarget);
                // notify callback
                if (this._commaSeperated) {
@@ -4175,7 +4180,12 @@ WCF.Search.Base = Class.extend({
                        }
                }
                else {
-                       var $clearSearchInput = this._callback($listItem.data());
+                       if (this._callback === null) {
+                               this._searchInput.val($listItem.data('label'));
+                       }
+                       else {
+                               $clearSearchInput = (this._callback($listItem.data()) === true) ? true : false;
+                       }
                }
 
                // close list and revert input