Hi there!

I'm newbie here - searching how to suggest a new feature I've already
implemented myself for my project.

As you all know Autocomplete give three ways to post data:

1. Throogh option { data : [...] }
2. Via external url with params
3. Via undocumented { source: function(term) { .. } } feature

But I am not happy with it. I am a Java warrior and I use superb DWR
lib for AJAX requests - so application have no controllers to handle
autocomplete control's request. I need a "external AJAX" feature. So,
I made it.

This is it

<pre>
------------------------------------------------------------------------------------

Index: web/jquery/ui/ui.autocomplete.js
===================================================================
--- web/jquery/ui/ui.autocomplete.js    (revision 101)
+++ web/jquery/ui/ui.autocomplete.js    Tue Dec 23 23:32:33 MSK 2008
@@ -326,7 +326,7 @@
                // if an AJAX url has been supplied, try loading the data now

                } else if( (typeof options.url == "string") && 
(options.url.length
> 0) ){
-
+
                        var extraParams = {
                                timestamp: +new Date()
                        };
@@ -359,6 +359,14 @@

                        cache.add(term, parsed);
                        success(term, parsed);
+        } else if (options.ajax && typeof options.ajax == 'function')
{
+            var dataCallback =
+                function(resultData) {
+                                       var parsed = options.parse && 
options.parse(resultData) || parse
(resultData);
+                                       cache.add(term, parsed);
+                                       success(term, parsed);
+                               };
+            options.ajax(term, dataCallback);
                } else {
                        // if we have a failure, we need to empty the list -- 
this
prevents the the [TAB] key from selecting the last successful match
                        select.emptyList();

------------------------------------------------------------------------------------
</pre>


The usage is like follows:

<pre>
function autocompleteCountries(term, dataCallback) {
  GeoRemoting.getCountries(
     function (list) { dataCallback(list.join("\n")); }
  );
}

$("#country")
                .attr("autocomplete", "off")
                .autocomplete({ ajax: autocompleteCountries, autoFill:
true});
</pre>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery UI" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jquery-ui?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to