@countriesdb/widget 0.1.20 → 0.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dom-manipulation.d.ts +1 -1
- package/dist/dom-manipulation.js +9 -2
- package/dist/index.esm.js +56 -24
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +56 -24
- package/dist/index.js.map +1 -1
- package/dist/initialization.d.ts +4 -0
- package/dist/initialization.js +6 -9
- package/package.json +1 -1
package/dist/initialization.js
CHANGED
|
@@ -20,8 +20,7 @@ export async function setupSubdivisionSelection(apiKey, backendUrl, state, confi
|
|
|
20
20
|
: null;
|
|
21
21
|
// Check if linked country select is multi-select (not allowed)
|
|
22
22
|
if (linkedCountrySelect && linkedCountrySelect.hasAttribute('multiple')) {
|
|
23
|
-
|
|
24
|
-
select.innerHTML = `<option value="${defaultValue}" disabled>Error: Cannot link to multi-select country. Use data-country-code instead.</option>`;
|
|
23
|
+
handleApiError(select, 'Cannot link to multi-select country. Use data-country-code instead.', true);
|
|
25
24
|
continue;
|
|
26
25
|
}
|
|
27
26
|
// No direct link → maybe data-country-code
|
|
@@ -31,8 +30,7 @@ export async function setupSubdivisionSelection(apiKey, backendUrl, state, confi
|
|
|
31
30
|
await updateSubdivisionSelect(select, apiKey, backendUrl, state, config, select.dataset.countryCode);
|
|
32
31
|
}
|
|
33
32
|
else {
|
|
34
|
-
|
|
35
|
-
select.innerHTML += `<option value="${defaultValue}" disabled>Error: No country select present</option>`;
|
|
33
|
+
handleApiError(select, 'No country select present');
|
|
36
34
|
}
|
|
37
35
|
}
|
|
38
36
|
// Always dispatch an update event for user-initiated subdivision changes
|
|
@@ -78,7 +76,8 @@ export async function updateSubdivisionSelect(select, apiKey, backendUrl, state,
|
|
|
78
76
|
// Use GeoIP only if data-preselected attribute is not set at all
|
|
79
77
|
const shouldUseGeoIP = preselectedValue === undefined || preselectedValue === null;
|
|
80
78
|
// Check if this subdivision select prefers official subdivisions
|
|
81
|
-
const preferOfficial = select.hasAttribute('data-prefer-official')
|
|
79
|
+
const preferOfficial = select.hasAttribute('data-prefer-official') ||
|
|
80
|
+
config.preferOfficialSubdivisions;
|
|
82
81
|
const languageHeaders = CountriesDBClient.getLanguageHeaders(config.forcedLanguage, config.defaultLanguage);
|
|
83
82
|
const subdivisionsResult = await CountriesDBClient.fetchSubdivisions({
|
|
84
83
|
apiKey,
|
|
@@ -175,8 +174,7 @@ export async function updateSubdivisionSelect(select, apiKey, backendUrl, state,
|
|
|
175
174
|
}
|
|
176
175
|
else if (!select.dataset.country ||
|
|
177
176
|
!document.querySelector(`.country-selection[data-name="${select.dataset.country}"]`)) {
|
|
178
|
-
|
|
179
|
-
select.innerHTML += `<option value="${defaultValue}" disabled>Error: No country select present</option>`;
|
|
177
|
+
handleApiError(select, 'No country select present');
|
|
180
178
|
}
|
|
181
179
|
}
|
|
182
180
|
/**
|
|
@@ -205,8 +203,7 @@ export async function setupCountrySelection(apiKey, backendUrl, state, config, s
|
|
|
205
203
|
if (name && seenNames[name]) {
|
|
206
204
|
select.removeAttribute('data-name');
|
|
207
205
|
initializeSelect(select, '—');
|
|
208
|
-
|
|
209
|
-
select.innerHTML += `<option value="${defaultValue}" disabled>Error: Duplicate field</option>`;
|
|
206
|
+
handleApiError(select, 'Duplicate field');
|
|
210
207
|
continue;
|
|
211
208
|
}
|
|
212
209
|
if (name) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@countriesdb/widget",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.22",
|
|
4
4
|
"description": "Country and state/province select widget with ISO 3166-1 and ISO 3166-2 codes. Auto-populates dropdowns with up-to-date country and subdivision data in multiple languages. Easy integration for forms, location selection, and address validation.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|