Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution : window.crs.populateRegionFields(countryElement, regionElement) **FOR "RELOADING" THE REGION SELECT** #57

Open
CreativeHouseDotOrg opened this issue Oct 2, 2017 · 2 comments

Comments

@CreativeHouseDotOrg
Copy link

CreativeHouseDotOrg commented Oct 2, 2017

Hello

I added 1 line of code in your plugin today and i wanted to "commit" my change here:

File:
jquery.crs.js (0.4.0)

Line 212:
(Added) populateRegionFields: _populateRegionFields

So I can call this specific row of code to update the Region Select after I'm setting the value via jQuery:

EXAMPLE
window.crs.init();
$.getJSON('//freegeoip.net/json/', function(result) {
$('#crs-country').val(result.country_code);
window.crs.populateRegionFields($('#crs-country')[0],$('#crs-region')[0]);
});

This Method will locate the current CountryCode from freegeoip.net and determine from which Country the Visitor is coming from and it will assign the value automatically to the Country Select and "repopulate" the Region Select with the current Country Select Value.

I hope I could help a little for others that run in to the same "issue" of a missing region reload method C:

Kind Regards

Mike of Creative-House.org

@wobblymusic
Copy link

This was really helpful. Two comments:

  1. You need to put a comma at the end of Line 211, i.e.
    return {
    init: _init,
    populateRegionFields: _populateRegionFields
    };

  2. While this does populate the regions field with the correct drop down list, it does not make the data-default-value the selected option. For that, you'll need to add a line like
    $("#crs-region").val($("#crs-region").attr("data-default-value"));

@wobblymusic
Copy link

Incidentally, there should be a way to write a method that does the same thing, but doesn't require any arguments. I'm not enough of a javascript wiz to figure it out. Thankfully, your simple change does the trick, albeit less elegantly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants