Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we use jQueryUI autocomplete with jQuery tags input plugin?

I want to merge two plugins together.

I am using jquery autocomplete for zipcode field.

Now I want to add multiple entries for zipcode field so I found jQuery tags input plugin.

So I wnat to use jQueryUI autocomplete with jQuery tags input plugin.

I tried myself on JSfiddle but not working. link :-http://jsfiddle.net/7aDak/1719/

Can anyone help me for this functionality.

like image 515
Akki Avatar asked Dec 21 '12 06:12

Akki


1 Answers

You met two problems here:

  • default param name used by autocomplete is "term" - no changeable by simple param, you need to do it by "source" function
  • result needs two fields: "label" and "value" with is not provided by your provider - need response remap.

Code below is good for startpoint for you:

$('#tag1').tagsInput({
autocomplete_url:'http://ws.geonames.org/postalCodeSearchJSON',
autocomplete:{
source: function(request, response) {
  $.ajax({
     url: "http://ws.geonames.org/postalCodeSearchJSON",
     dataType: "json",
     data: {
        postalcode_startsWith: request.term
     },
     success: function(data) {
        response( $.map( data.postalCodes, function( item ) {
                        return {
                            label: item.countryCode + "-" + item.placeName,
                            value: item.postalCode
                        }
                    }));
     }
  })
}}});

http://jsfiddle.net/YGm89/

like image 71
Saram Avatar answered Nov 15 '22 11:11

Saram