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.

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? Commented Dec 23, 2012 at 16:22

1 Answer 1

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/

Sign up to request clarification or add additional context in comments.

2 Comments

thanks Saram..! actually I have done it in same as above before u telling. I just forgot to answer my own question.Thanks
above code snippet throwing script error in jsfilldle

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.