ubilabs / geocomplete

jQuery Geocoding and Places Autocomplete Plugin
http://ubilabs.github.com/geocomplete/
MIT License
1.22k stars 406 forks source link

Reinitialize geocomplete({...}); #255

Open anupalhub opened 8 years ago

anupalhub commented 8 years ago

Hi everyone,

Looking for a quick answer. Please help. I want to reinitialize the geocomplete when ever country select box changes. I am restricting result for selected country.

My code:

var initGeoComplete = function (){
        var country = $('#geoCountry').val();
        //country = country || 'in';
        $("#searchGeoLocation").geocomplete({
            details: ".search-geo-details",
            detailsAttribute: "data-geo",
            componentRestrictions: {country: country}
        });
    };

I am trying to reinitialize the input with new geocomplete with different country everytime the country select #geoCountry changes. But results remains same with what it was initially set.

$(document).on('change', "#geoCountry", function () {
        initGeoComplete();
    });

Quick help is highly appreciated.

frandibar commented 8 years ago

Hi, I had the same problem and solved it using this hack: $('input').geocomplete('options').componentRestrictions.country = country;

anupalhub commented 8 years ago

@frandibar ok i will try that. Thanks though.