Can we use jQueryUI autocomplete with jQuery tags input plugin?
Asked Answered
N

1

6

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.

Newfangled answered 21/12, 2012 at 6:20 Comment(1)
I believe tagsInput is powered by autocomplete. In fact, there's a demo on the project home page that demonstrates autocomplete functionality. What problems are you having, exactly?Auberon
S
10

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/

Sunder answered 2/1, 2013 at 13:46 Comment(2)
thanks Saram..! actually I have done it in same as above before u telling. I just forgot to answer my own question.ThanksNewfangled
above code snippet throwing script error in jsfilldleHom

© 2022 - 2024 — McMap. All rights reserved.