Skip to content

Commit

Permalink
Merge pull request #1 from chung1905/fix-data-default-value
Browse files Browse the repository at this point in the history
Fix data-default-value not set for region if only 1 country
  • Loading branch information
chung1905 authored Nov 2, 2021
2 parents 7de1761 + 5cadc91 commit 0531424
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion dist/crs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/crs.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/jquery.crs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/jquery.crs.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion source/source-crs.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
};

// if the country dropdown has a default value, populate the region field as well
if (defaultSelectedValue !== null && countryElement.selectedIndex > 0) {
if (defaultSelectedValue !== null && countryElement.selectedIndex >= _showEmptyCountryOption) {
_populateRegionFields(countryElement, regionElement);

var defaultRegionSelectedValue = regionElement.getAttribute("data-default-value");
Expand Down
6 changes: 3 additions & 3 deletions source/source-jquery.crs.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
});

// if the country dropdown has a default value, populate the region field as well
if (defaultSelectedValue && countryElement.selectedIndex > 0) {
if (defaultSelectedValue && countryElement.selectedIndex >= _showEmptyCountryOption) {
_populateRegionFields(countryElement, regionElement);

var defaultRegionSelectedValue = $(regionElement).attr("data-default-value");
Expand Down Expand Up @@ -208,7 +208,7 @@

var weWantAndHaveShortCodes = displayType === 'shortcode' && regionData.hasShortcodes;
var indexToSort = weWantAndHaveShortCodes ? 1 : 0;
regionData.regions.sort(function(a, b) {
regionData.regions.sort(function (a, b) {
var x = a[indexToSort].toLowerCase();
var y = b[indexToSort].toLowerCase();
return x < y ? -1 : x > y ? 1 : 0;
Expand Down Expand Up @@ -245,7 +245,7 @@
}

// now prepend the preferred countries
for (var i=0; i<preferredShortCodes.length; i++) {
for (var i = 0; i < preferredShortCodes.length; i++) {
var code = preferredShortCodes[i];
updatedCountries.unshift(preferredMap[code]);
}
Expand Down

0 comments on commit 0531424

Please sign in to comment.